Automap (client) [VS plugin mod]
Revision | 7d0b7c5c801c5411bd8fa9c78cbb0e219d0572c2 (tree) |
---|---|
Time | 2020-04-26 05:55:25 |
Author | melchior <melchior@user...> |
Commiter | melchior |
Potential fix for Memory leak - Clear (some) Metadata post persist
@@ -128,18 +128,22 @@ namespace Automap | ||
128 | 128 | [ProtoAfterDeserialization] |
129 | 129 | private void PostProcess() |
130 | 130 | { |
131 | - if (this.HeightMap == null) this.HeightMap = new ushort[ChunkSize, ChunkSize]; | |
131 | + ChunkSize = (ChunkSize == byte.MinValue) ? (byte)32 : ChunkSize;//Not good - if chunk wasn't 32 orignally! | |
132 | + | |
133 | + if (this.HeightMap == null || this.HeightMap.Length != (ChunkSize * ChunkSize)) { | |
134 | + this.HeightMap = new ushort[ChunkSize, ChunkSize]; | |
135 | + } | |
132 | 136 | |
133 | 137 | if (_flattened_HeightMap != null) |
134 | 138 | { |
135 | 139 | int col, row; |
136 | - _ = new BitVector32(0); | |
140 | + var bitMasker = new BitVector32(0); | |
137 | 141 | var rowSection = BitVector32.CreateSection((short) (ChunkSize - 1)); |
138 | 142 | var colSection = BitVector32.CreateSection((short) (ChunkSize - 1), rowSection); |
139 | 143 | |
140 | 144 | for (uint rowcol = 0; rowcol < (ChunkSize * ChunkSize); rowcol++) |
141 | 145 | { |
142 | - BitVector32 bitMasker = new BitVector32(data: (int) rowcol); | |
146 | + bitMasker = new BitVector32(data: (int) rowcol); | |
143 | 147 | row = bitMasker[rowSection]; |
144 | 148 | col = bitMasker[colSection]; |
145 | 149 | HeightMap[col, row] = _flattened_HeightMap[rowcol]; |
@@ -231,5 +235,14 @@ namespace Automap | ||
231 | 235 | base.Add(newItem); |
232 | 236 | } |
233 | 237 | |
238 | + public void ClearMetadata( ) | |
239 | + { | |
240 | + for (int i = 0, maxItemsCount = this.Items.Count; i < maxItemsCount; i++) { | |
241 | + ColumnMeta entry = this.Items[i]; | |
242 | + entry.HeightMap = null; | |
243 | + entry.RockRatio = null;//Also regenerated when any chunk in a column is changed... | |
244 | + } | |
245 | + } | |
246 | + | |
234 | 247 | } |
235 | -} | |
\ No newline at end of file | ||
248 | +} |
@@ -53,7 +53,7 @@ namespace Automap | ||
53 | 53 | |
54 | 54 | internal CommandType CurrentState { get; set; } |
55 | 55 | //Run status, Chunks processed, stats, center of map.... |
56 | - private uint nullChunkCount, updatedChunksTotal; | |
56 | + private uint nullChunkCount, nullMapCount, updatedChunksTotal; | |
57 | 57 | private Vec2i startChunkColumn; |
58 | 58 | |
59 | 59 | private readonly int chunkSize; |
@@ -184,7 +184,7 @@ namespace Automap | ||
184 | 184 | if (mapChunk == null) |
185 | 185 | { |
186 | 186 | Logger.Warning("SKIP CHUNK: ({0}) - Map Chunk NULL!", mostActiveCol.Key); |
187 | - nullChunkCount++; | |
187 | + nullMapCount++; | |
188 | 188 | columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem); |
189 | 189 | continue; |
190 | 190 | } |
@@ -219,8 +219,9 @@ namespace Automap | ||
219 | 219 | columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem); |
220 | 220 | Logger.VerboseDebug("Un-painted chunk: ({0}) ", mostActiveCol.Key); |
221 | 221 | } |
222 | - | |
223 | 222 | } |
223 | + //Cleanup persisted Metadata... | |
224 | + chunkTopMetadata.ClearMetadata( ); | |
224 | 225 | } |
225 | 226 | |
226 | 227 | UpdateStatus(this.updatedChunksTotal, this.nullChunkCount, updatedChunks); |
@@ -500,6 +501,7 @@ namespace Automap | ||
500 | 501 | #if DEBUG |
501 | 502 | Logger.VerboseDebug("Chunk null or empty X{0} Y{1} Z{2}", key.X, targetChunkY, key.Y); |
502 | 503 | #endif |
504 | + nullChunkCount++; | |
503 | 505 | continue; |
504 | 506 | } |
505 | 507 |
@@ -512,14 +514,12 @@ namespace Automap | ||
512 | 514 | |
513 | 515 | foreach (var blockEnt in chunkData.BlockEntities) |
514 | 516 | { |
515 | - | |
516 | 517 | if (blockEnt != null && blockEnt.Block != null && BlockID_Designators.ContainsKey(blockEnt.Block.BlockId)) |
517 | 518 | { |
518 | 519 | var designator = BlockID_Designators[blockEnt.Block.BlockId]; |
519 | 520 | designator.SpecialAction(ClientAPI, POIs, blockEnt.Pos.Copy(), blockEnt.Block); |
520 | 521 | } |
521 | 522 | } |
522 | - | |
523 | 523 | } |
524 | 524 | /********************* Chunk/Column BLOCKs scanning ****************/ |
525 | 525 | //Heightmap, Stats, block tally |
@@ -528,6 +528,10 @@ namespace Automap | ||
528 | 528 | int X_index, Y_index, Z_index; |
529 | 529 | X_index = Y_index = Z_index = 0; |
530 | 530 | |
531 | + //Ensure ChunkData Metadata fields arn't null...due to being tossed out | |
532 | + if (chunkMeta.HeightMap == null) { chunkMeta.HeightMap = new ushort[chunkSize, chunkSize]; } | |
533 | + if (chunkMeta.RockRatio == null) { chunkMeta.RockRatio = new Dictionary<int, uint>(10); } | |
534 | + | |
531 | 535 | do |
532 | 536 | { |
533 | 537 | do |