jondewoo / UnitySlippyMap

A slippy map implementation written in C# for Unity3D
304 stars 110 forks source link

cacheSize is incorrectly calculated #1

Closed jhjulkun closed 11 years ago

jhjulkun commented 11 years ago

Delete contents of your cache directory (on Mac ~/Library/Caches/unity.reallyreallyreal.SlippyMap)

While running check how much disk space the map is using: watch -n 1 du -hs ~/Library/Caches/unity.reallyreallyreal.SlippyMap

The disk will go up to the limit correctly, but then it will start shrinking, it seems like the cacheSize is not keeping track of what's actually on disk, only pending loads.

If you don't have the 'watch' command install darwin ports, then 'sudo port install watch', or just du manually every now and then.

http://www.macports.org/

jondewoo commented 11 years ago

Fixed in commit #3e0e269727a0c8270f33f468751e8526c0678a1e. Thanks!

jhjulkun commented 11 years ago

Better. But it seems like a TileEntry can still be listed many times, but its only physically on disk once.

CacheCheck: matched /Users/heikki/Library/Caches/unity.reallyreallyreal.SlippyMap/e87694c8-d5b5-47b3-b282-9ce6aad2fe6a.png 2 times CacheCheck: tile/file/match mismatch 14/10/13 CacheCheck: cacheSize mismatch 2008652/1874131

I wrote a simple checker, see below, just call it after any changes, and when initially loading the tiles.

To see mismatch faster, change MaxCacheSize to something small, scroll around a bit, quit and then restart and you'll see some errors.

public int              MaxCacheSize = 2000000; // 2 Mo JHJ

      private void CacheCheck()
    {
            string[] cacheFiles = Directory.GetFiles(Application.persistentDataPath, "*.png");

            int numMatches=0;
            long fileCacheSize=0;
            int numFiles=0;
            int errors=0;

            foreach (string name in cacheFiles)
            {
                    numFiles++;
                    int tileFound=0;

                    foreach (TileEntry tile in tiles)
                    {
                            string fileName = Application.persistentDataPath + "/" + tile.guid + ".png";

                            if (name == fileName) {
                                    FileInfo f = new FileInfo(fileName);
                                    fileCacheSize += f.Length;
                                    if (tile.size != f.Length) {
                                            Debug.Log("CacheCheck: incorrect length for " + fileName + "tile.size=" + tile.size + "fileSize=" + f.Length);
                                    }
                                    numMatches++;
                                    tileFound++;
                            }
                    }
                    if (tileFound==0) {
                            Debug.Log("CacheCheck: never matched " + name);
                            errors++;
                    }
                    if (tileFound>1) {
                            Debug.Log("CacheCheck: matched " + name + " " + tileFound + " times");
                            errors++;
                    }
            }
            if (tiles.Count != numFiles || tiles.Count != numMatches) {
                    Debug.Log("CacheCheck: tile/file/match mismatch " + tiles.Count + "/" + numFiles + "/" + numMatches);
                    errors++;
            }
            if (cacheSize != fileCacheSize) {
                    Debug.Log("CacheCheck: cacheSize mismatch " + cacheSize + "/" + fileCacheSize);
                    errors++;
            }
            if (errors==0) {
                    Debug.Log("CacheCheck: Passed tests!");
            }
}