OSDN Git Service

Fix for B.E error invoke, Anti-Duplication
authormelchior <melchior@users.osdn.me>
Fri, 3 Jun 2022 23:59:42 +0000 (19:59 -0400)
committermelchior <melchior@users.osdn.me>
Fri, 3 Jun 2022 23:59:42 +0000 (19:59 -0400)
prevent ConcurrentDict; duplicate on platforms that happen to make no
assurace of unique keyswhen Enum'ing,
plus assorted minor fixes...

Automap/Designators/DefaultDesignators.cs
Automap/Renderers/StandardRenderer.cs
Automap/Subsystems/AutomapSystem.cs

index 4179f38..c8e25c1 100644 (file)
@@ -167,7 +167,7 @@ namespace Automap
                //sign post Text into a POI field...
                BlockEntitySignPost signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySignPost;
 
-               if (signEntity != null && signEntity.textByCardinalDirection?.Length > 0) {
+               if (signEntity != null && signEntity.textByCardinalDirection != null && signEntity.textByCardinalDirection?.Length > 0) {
 
                var textTemp = SaferUnicodeEncoding.GetBytes(string.Join(",", signEntity.textByCardinalDirection));
 
@@ -191,7 +191,9 @@ namespace Automap
                //clientAPI.Logger.VerboseDebug("Trader: {0} @ {1}", entity.GetName(), posn);
 
                var traderJoe = entity as EntityTrader;
-               var traderName = entity.GetBehavior<EntityBehaviorNameTag>( )?.DisplayName;
+               if (traderJoe == null) return;
+               
+               var traderName = entity.GetBehavior<EntityBehaviorNameTag>( )?.DisplayName ?? @"?";
                string code;
                // this makes me ill
                switch (entity.Code.Path) {
index 1a56ba9..df45565 100644 (file)
@@ -152,6 +152,7 @@ namespace Automap
                #if DEBUG
                Logger.VerboseDebug("Gap in chunk-column at render time Chunk-Y:{0}", localChunkY);
                #endif
+               if (localChunkY == 0 ) break;
                continue;
                }
 
index 6770ecf..249151c 100644 (file)
@@ -134,8 +134,7 @@ namespace Automap
                columnCounters.AddOrUpdate(topPosition, 
                                              new ColumnCounter(chunkSize, newOrEdit, chunkCoord), 
                                              (chkPos, chkChng) => chkChng.Update(chunkCoord, chunkSize, newOrEdit)
-                                            );
-               
+                                            );         
                }
 
                /// <summary>
@@ -220,7 +219,7 @@ namespace Automap
                Logger.VerboseDebug("(re)Created meta-chunk {0}", revisitCoord);
                #endif
                }
-
+               //TODO: Double validation of....?
                ProcessChunkBlocks(revisitCoord, rv_mapChunk, ref rv_chunkMeta);
 
                ChunkRenderer.SetupPngImage(revisitCoord, path, _chunkPath, ref rv_chunkMeta);
@@ -237,12 +236,12 @@ namespace Automap
                }//*********** REVISIT'd ******************
                
                if (!columnCounters.IsEmpty)
-                               {//-- Should dodge enumerator changing underfoot....at a cost.
-                               var tempSet = columnCounters.ToArray().Where(cks => cks.Value.WeightedSum > editThreshold) .OrderByDescending(kvp => kvp.Value.WeightedSum);
+                               {//Resulting snapshot keys mabey NON-UNIQUE!!! a *FEATURE* of ConcurrentDict !
+                                       var columnsSnapshot = columnCounters.Where(cks => cks.Value.WeightedSum > editThreshold).OrderByDescending(kvp => kvp.Value.WeightedSum).ToArray( );
 
                                        UpdateEntityMetadata();
 
-                                       foreach (var mostActiveCol in tempSet)
+                                       foreach (var mostActiveCol in columnsSnapshot)
                                        {
                                                var mapChunk = ClientAPI.World.BlockAccessor.GetMapChunk(mostActiveCol.Key);
 
@@ -272,11 +271,20 @@ namespace Automap
                                                        Logger.VerboseDebug("Created meta-chunk {0}", mostActiveCol.Key);
                                                        #endif
                                                }
+
+                                               /********* Special Interlock with C.D. *************/
+                                               if (columnCounters.TryRemove(mostActiveCol.Key, out ejectedItem)) {
                                                ProcessChunkBlocks(mostActiveCol.Key, mapChunk, ref chunkMeta);
-                                               mostActiveCol.Value.SetCutoff(chunkMeta.YMax / chunkSize);
+                                               ejectedItem.SetCutoff(chunkMeta.YMax / chunkSize);
 
                                                ChunkRenderer.SetupPngImage(mostActiveCol.Key, path, _chunkPath, ref chunkMeta);
                                                ChunkRenderer.GenerateChunkPngShard(mostActiveCol.Key, mapChunk, chunkMeta, ref chunkTopMetadata, out updatedPixels);
+                                               }
+                                               else {
+                                               #if DEBUG
+                                               Logger.Warning("Prevented duplicate processing of: {0}",mostActiveCol.Key );
+                                               #endif
+                                               }
 
                                                if (updatedPixels > 0)
                                                {
@@ -285,11 +293,11 @@ namespace Automap
                                                        #endif
                                                        updatedChunks++;
                                                        chunkTopMetadata.Update(chunkMeta);
-                                                       columnCounters.TryRemove(mostActiveCol.Key, out ejectedItem);
+                                                       //columnCounters.TryRemove(mostActiveCol.Key, out ejectedItem);
                                                }
                                                else
                                                {
-                                                       columnCounters.TryRemove(mostActiveCol.Key, out ejectedItem);
+                                                       //columnCounters.TryRemove(mostActiveCol.Key, out ejectedItem);
                                                        #if DEBUG
                                                        Logger.VerboseDebug("Un-painted chunk shard: ({0}) ", mostActiveCol.Key);
                                                        #endif
@@ -678,10 +686,10 @@ namespace Automap
                        {
                                WorldChunk worldChunk = ClientAPI.World.BlockAccessor.GetChunk(key.X, targetChunkY, key.Y) as WorldChunk;
 
-                               if (worldChunk == null || worldChunk.BlockEntities == null)
+                               if (worldChunk == null || worldChunk.BlockEntities == null || worldChunk.Disposed)
                                {
                                        #if DEBUG
-                                       Logger.VerboseDebug("WORLD chunk: null, B.E. null X{0} Y{1} Z{2} !", key.X, targetChunkY, key.Y);
+                                       Logger.VerboseDebug("WORLD chunk, null/disposed OR B.E. null: X{0} Y{1} Z{2} !", key.X, targetChunkY, key.Y);
                                        #endif
                                        nullChunkCount++;
                                        continue;
@@ -705,15 +713,18 @@ namespace Automap
                                if (worldChunk.BlockEntities != null && worldChunk.BlockEntities.Count > 0)
                                {
                                        #if DEBUG
-                                       Logger.VerboseDebug("Scan pos.({0}) for BlockEntities# {1}", key, worldChunk.BlockEntities.Count);
+                                       Logger.VerboseDebug("Scan in Chunk:({0}, Y {2}):  found {1} BlockEntities", key, worldChunk.BlockEntities.Count,targetChunkY);
                                        #endif
 
                                        foreach (var blockEnt in worldChunk.BlockEntities)
                                        {
-                                               if (blockEnt.Key != null && blockEnt.Value != null && blockEnt.Value.Block != null && blockEnt.Value.Pos != null  && BlockID_Designators.ContainsKey(blockEnt.Value.Block.BlockId))
+                                       var blockEntityPos = blockEnt.Key;
+                                       var blockEntity = blockEnt.Value;
+                                       if (blockEntityPos == null || blockEntity == null ) continue;
+                                       if (blockEntity.Block != null && !blockEntity.Block.IsMissing &&  BlockID_Designators.ContainsKey(blockEntity.Block.BlockId))
                                                {
                                                        var designator = BlockID_Designators[blockEnt.Value.Block.BlockId];
-                                                       designator?.SpecialAction(ClientAPI, POIs, blockEnt.Value.Pos.Copy(), blockEnt.Value.Block);
+                                                       if (designator != null && designator.SpecialAction != null) designator.SpecialAction(ClientAPI, POIs, blockEnt.Value.Pos.Copy(), blockEnt.Value.Block);
                                                }
                                        }
                                }