🚨 Free the block index when a landscape update fails mid-packet

This commit is contained in:
2026-11-15 22:06:51 +01:00
parent 3df6ab93f6
commit 1dc371ed27
+22 -19
View File
@@ -770,30 +770,33 @@ var
block: TBlock; block: TBlock;
begin begin
index := TGenericIndex.Create(nil); index := TGenericIndex.Create(nil);
while ABuffer.Position < ABuffer.Size do try
begin while ABuffer.Position < ABuffer.Size do
ABuffer.Read(coords, SizeOf(TBlockCoords)); begin
id := GetID(coords.X, coords.Y); ABuffer.Read(coords, SizeOf(TBlockCoords));
id := GetID(coords.X, coords.Y);
map := TMapBlock.Create(ABuffer, coords.X, coords.Y); map := TMapBlock.Create(ABuffer, coords.X, coords.Y);
count := ABuffer.ReadWord; count := ABuffer.ReadWord;
if count > 0 then if count > 0 then
index.Lookup := ABuffer.Position index.Lookup := ABuffer.Position
else else
index.Lookup := -1; index.Lookup := -1;
index.Size := count * 7; index.Size := count * 7;
statics := TSeperatedStaticBlock.Create(ABuffer, index, coords.X, coords.Y); statics := TSeperatedStaticBlock.Create(ABuffer, index, coords.X, coords.Y);
FBlockCache.RemoveID(id); FBlockCache.RemoveID(id);
block := TBlock.Create(map, statics); block := TBlock.Create(map, statics);
block.UpdateBlockAcess(Self); block.UpdateBlockAcess(Self);
FBlockCache.StoreID(id, block); FBlockCache.StoreID(id, block);
FOpenRequests[coords.Y * FWidth + coords.X] := False; FOpenRequests[coords.Y * FWidth + coords.X] := False;
if Assigned(FOnNewBlock) then FOnNewBlock(block); if Assigned(FOnNewBlock) then FOnNewBlock(block);
end;
finally
index.Free;
end; end;
index.Free;
end; end;
procedure TLandscape.OnDrawMapPacket(ABuffer: TEnhancedMemoryStream); procedure TLandscape.OnDrawMapPacket(ABuffer: TEnhancedMemoryStream);