Automap (OSS) GIT software repository
Revision | 8ed1a1e5a9e3a9699b2aae545bd2cfe2ca02d659 (tree) |
---|---|
Time | 2022-06-04 08:59:42 |
Author | ![]() |
Commiter | melchior |
Fix for B.E error invoke, Anti-Duplication
prevent ConcurrentDict; duplicate on platforms that happen to make no
assurace of unique keyswhen Enum'ing,
plus assorted minor fixes...
@@ -167,7 +167,7 @@ namespace Automap | ||
167 | 167 | //sign post Text into a POI field... |
168 | 168 | BlockEntitySignPost signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySignPost; |
169 | 169 | |
170 | - if (signEntity != null && signEntity.textByCardinalDirection?.Length > 0) { | |
170 | + if (signEntity != null && signEntity.textByCardinalDirection != null && signEntity.textByCardinalDirection?.Length > 0) { | |
171 | 171 | |
172 | 172 | var textTemp = SaferUnicodeEncoding.GetBytes(string.Join(",", signEntity.textByCardinalDirection)); |
173 | 173 |
@@ -191,7 +191,9 @@ namespace Automap | ||
191 | 191 | //clientAPI.Logger.VerboseDebug("Trader: {0} @ {1}", entity.GetName(), posn); |
192 | 192 | |
193 | 193 | var traderJoe = entity as EntityTrader; |
194 | - var traderName = entity.GetBehavior<EntityBehaviorNameTag>( )?.DisplayName; | |
194 | + if (traderJoe == null) return; | |
195 | + | |
196 | + var traderName = entity.GetBehavior<EntityBehaviorNameTag>( )?.DisplayName ?? @"?"; | |
195 | 197 | string code; |
196 | 198 | // this makes me ill |
197 | 199 | switch (entity.Code.Path) { |
@@ -152,6 +152,7 @@ namespace Automap | ||
152 | 152 | #if DEBUG |
153 | 153 | Logger.VerboseDebug("Gap in chunk-column at render time Chunk-Y:{0}", localChunkY); |
154 | 154 | #endif |
155 | + if (localChunkY == 0 ) break; | |
155 | 156 | continue; |
156 | 157 | } |
157 | 158 |
@@ -134,8 +134,7 @@ namespace Automap | ||
134 | 134 | columnCounters.AddOrUpdate(topPosition, |
135 | 135 | new ColumnCounter(chunkSize, newOrEdit, chunkCoord), |
136 | 136 | (chkPos, chkChng) => chkChng.Update(chunkCoord, chunkSize, newOrEdit) |
137 | - ); | |
138 | - | |
137 | + ); | |
139 | 138 | } |
140 | 139 | |
141 | 140 | /// <summary> |
@@ -220,7 +219,7 @@ namespace Automap | ||
220 | 219 | Logger.VerboseDebug("(re)Created meta-chunk {0}", revisitCoord); |
221 | 220 | #endif |
222 | 221 | } |
223 | - | |
222 | + //TODO: Double validation of....? | |
224 | 223 | ProcessChunkBlocks(revisitCoord, rv_mapChunk, ref rv_chunkMeta); |
225 | 224 | |
226 | 225 | ChunkRenderer.SetupPngImage(revisitCoord, path, _chunkPath, ref rv_chunkMeta); |
@@ -237,12 +236,12 @@ namespace Automap | ||
237 | 236 | }//*********** REVISIT'd ****************** |
238 | 237 | |
239 | 238 | if (!columnCounters.IsEmpty) |
240 | - {//-- Should dodge enumerator changing underfoot....at a cost. | |
241 | - var tempSet = columnCounters.ToArray().Where(cks => cks.Value.WeightedSum > editThreshold) .OrderByDescending(kvp => kvp.Value.WeightedSum); | |
239 | + {//Resulting snapshot keys mabey NON-UNIQUE!!! a *FEATURE* of ConcurrentDict ! | |
240 | + var columnsSnapshot = columnCounters.Where(cks => cks.Value.WeightedSum > editThreshold).OrderByDescending(kvp => kvp.Value.WeightedSum).ToArray( ); | |
242 | 241 | |
243 | 242 | UpdateEntityMetadata(); |
244 | 243 | |
245 | - foreach (var mostActiveCol in tempSet) | |
244 | + foreach (var mostActiveCol in columnsSnapshot) | |
246 | 245 | { |
247 | 246 | var mapChunk = ClientAPI.World.BlockAccessor.GetMapChunk(mostActiveCol.Key); |
248 | 247 |
@@ -272,11 +271,20 @@ namespace Automap | ||
272 | 271 | Logger.VerboseDebug("Created meta-chunk {0}", mostActiveCol.Key); |
273 | 272 | #endif |
274 | 273 | } |
274 | + | |
275 | + /********* Special Interlock with C.D. *************/ | |
276 | + if (columnCounters.TryRemove(mostActiveCol.Key, out ejectedItem)) { | |
275 | 277 | ProcessChunkBlocks(mostActiveCol.Key, mapChunk, ref chunkMeta); |
276 | - mostActiveCol.Value.SetCutoff(chunkMeta.YMax / chunkSize); | |
278 | + ejectedItem.SetCutoff(chunkMeta.YMax / chunkSize); | |
277 | 279 | |
278 | 280 | ChunkRenderer.SetupPngImage(mostActiveCol.Key, path, _chunkPath, ref chunkMeta); |
279 | 281 | ChunkRenderer.GenerateChunkPngShard(mostActiveCol.Key, mapChunk, chunkMeta, ref chunkTopMetadata, out updatedPixels); |
282 | + } | |
283 | + else { | |
284 | + #if DEBUG | |
285 | + Logger.Warning("Prevented duplicate processing of: {0}",mostActiveCol.Key ); | |
286 | + #endif | |
287 | + } | |
280 | 288 | |
281 | 289 | if (updatedPixels > 0) |
282 | 290 | { |
@@ -285,11 +293,11 @@ namespace Automap | ||
285 | 293 | #endif |
286 | 294 | updatedChunks++; |
287 | 295 | chunkTopMetadata.Update(chunkMeta); |
288 | - columnCounters.TryRemove(mostActiveCol.Key, out ejectedItem); | |
296 | + //columnCounters.TryRemove(mostActiveCol.Key, out ejectedItem); | |
289 | 297 | } |
290 | 298 | else |
291 | 299 | { |
292 | - columnCounters.TryRemove(mostActiveCol.Key, out ejectedItem); | |
300 | + //columnCounters.TryRemove(mostActiveCol.Key, out ejectedItem); | |
293 | 301 | #if DEBUG |
294 | 302 | Logger.VerboseDebug("Un-painted chunk shard: ({0}) ", mostActiveCol.Key); |
295 | 303 | #endif |
@@ -678,10 +686,10 @@ namespace Automap | ||
678 | 686 | { |
679 | 687 | WorldChunk worldChunk = ClientAPI.World.BlockAccessor.GetChunk(key.X, targetChunkY, key.Y) as WorldChunk; |
680 | 688 | |
681 | - if (worldChunk == null || worldChunk.BlockEntities == null) | |
689 | + if (worldChunk == null || worldChunk.BlockEntities == null || worldChunk.Disposed) | |
682 | 690 | { |
683 | 691 | #if DEBUG |
684 | - Logger.VerboseDebug("WORLD chunk: null, B.E. null X{0} Y{1} Z{2} !", key.X, targetChunkY, key.Y); | |
692 | + Logger.VerboseDebug("WORLD chunk, null/disposed OR B.E. null: X{0} Y{1} Z{2} !", key.X, targetChunkY, key.Y); | |
685 | 693 | #endif |
686 | 694 | nullChunkCount++; |
687 | 695 | continue; |
@@ -705,15 +713,18 @@ namespace Automap | ||
705 | 713 | if (worldChunk.BlockEntities != null && worldChunk.BlockEntities.Count > 0) |
706 | 714 | { |
707 | 715 | #if DEBUG |
708 | - Logger.VerboseDebug("Scan pos.({0}) for BlockEntities# {1}", key, worldChunk.BlockEntities.Count); | |
716 | + Logger.VerboseDebug("Scan in Chunk:({0}, Y {2}): found {1} BlockEntities", key, worldChunk.BlockEntities.Count,targetChunkY); | |
709 | 717 | #endif |
710 | 718 | |
711 | 719 | foreach (var blockEnt in worldChunk.BlockEntities) |
712 | 720 | { |
713 | - if (blockEnt.Key != null && blockEnt.Value != null && blockEnt.Value.Block != null && blockEnt.Value.Pos != null && BlockID_Designators.ContainsKey(blockEnt.Value.Block.BlockId)) | |
721 | + var blockEntityPos = blockEnt.Key; | |
722 | + var blockEntity = blockEnt.Value; | |
723 | + if (blockEntityPos == null || blockEntity == null ) continue; | |
724 | + if (blockEntity.Block != null && !blockEntity.Block.IsMissing && BlockID_Designators.ContainsKey(blockEntity.Block.BlockId)) | |
714 | 725 | { |
715 | 726 | var designator = BlockID_Designators[blockEnt.Value.Block.BlockId]; |
716 | - designator?.SpecialAction(ClientAPI, POIs, blockEnt.Value.Pos.Copy(), blockEnt.Value.Block); | |
727 | + if (designator != null && designator.SpecialAction != null) designator.SpecialAction(ClientAPI, POIs, blockEnt.Value.Pos.Copy(), blockEnt.Value.Block); | |
717 | 728 | } |
718 | 729 | } |
719 | 730 | } |