OSDN Git Service

FIX: Temporary chunks list to avoid Enumerator mutation
authormelchior <melchior@users.osdn.me>
Wed, 11 Dec 2019 00:25:37 +0000 (19:25 -0500)
committermelchior <melchior@users.osdn.me>
Wed, 11 Dec 2019 00:25:37 +0000 (19:25 -0500)
Automap/Automap_Internals.cs

index a0a763e..6110a8e 100644 (file)
@@ -45,7 +45,7 @@ namespace Automap
                private void StartAutomap( )
                {
                path = ClientAPI.GetOrCreateDataPath(_mapPath);
-               path = ClientAPI.GetOrCreateDataPath(Path.Combine(path, "World_" + ClientAPI.World.Seed));
+               path = ClientAPI.GetOrCreateDataPath(Path.Combine(path, "World_" + ClientAPI.World.Seed));//Add name of World too!
 
                stylesFile = ClientAPI.World.AssetManager.Get(new AssetLocation(_domain, "config/automap_format.css"));
                Logger.VerboseDebug("CSS loaded: {0} size: {1}",stylesFile.IsLoaded() ,stylesFile.ToText( ).Length);
@@ -107,11 +107,12 @@ namespace Automap
                uint ejectedItem = 0;
                uint updatedChunks = 0;
 
-               while (columnCounter.Count > 0) {
-               //BUG:WIN crash here; Possibly "First()", edit race-cond?
-               var mostActiveCol = columnCounter.OrderByDescending(kvp => kvp.Value).First( );//FIX?
-               var mapChunk = ClientAPI.World.BlockAccessor.GetMapChunk(mostActiveCol.Key);
+               //-- Should dodge enumerator changing underfoot....at a cost.
+               if (!columnCounter.IsEmpty) {
+               var tempSet = columnCounter.ToArray( ).OrderByDescending(kvp => kvp.Value);
+               foreach (var mostActiveCol in tempSet) {
 
+               var mapChunk = ClientAPI.World.BlockAccessor.GetMapChunk(mostActiveCol.Key);
 
                if (mapChunk == null) {
                Logger.Warning("SKIP CHUNK: ({0}) - Map Chunk NULL!", mostActiveCol.Key);
@@ -141,6 +142,7 @@ namespace Automap
                }
 
                }
+               }
 
                if (updatedChunks > 0) {
                lastUpdate = updatedChunks;