🚨 Free the light collection when the light map update fails

This commit is contained in:
2026-11-15 22:08:32 +01:00
parent 3dd9ce1d68
commit 043a5a1ccf
+33 -31
View File
@@ -285,44 +285,46 @@ begin
{Logger.Send([lcClient, lcDebug], 'AWidth', AWidth); {Logger.Send([lcClient, lcDebug], 'AWidth', AWidth);
Logger.Send([lcClient, lcDebug], 'AHeight', AHeight);} Logger.Send([lcClient, lcDebug], 'AHeight', AHeight);}
lights := TWorldItemList.Create(False); lights := TWorldItemList.Create(False);
SetLength(tileMap, AWidth, AHeight); try
for x := 0 to AWidth - 1 do SetLength(tileMap, AWidth, AHeight);
for y := 0 to AHeight - 1 do for x := 0 to AWidth - 1 do
tileMap[x,y] := nil; for y := 0 to AHeight - 1 do
tileMap[x,y] := nil;
blockInfo := nil; blockInfo := nil;
while AScreenBuffer.Iterate(blockInfo) do while AScreenBuffer.Iterate(blockInfo) do
begin
if blockInfo^.State = ssNormal then
begin begin
if blockInfo^.Item is TStaticItem then if blockInfo^.State = ssNormal then
tileID := blockInfo^.Item.TileID + $4000 begin
else if blockInfo^.Item is TStaticItem then
tileID := blockInfo^.Item.TileID; tileID := blockInfo^.Item.TileID + $4000
tileData := ResMan.Tiledata.TileData[tileID]; else
tileID := blockInfo^.Item.TileID;
tileData := ResMan.Tiledata.TileData[tileID];
if tdfLightSource in tileData.Flags then if tdfLightSource in tileData.Flags then
lights.Add(blockInfo^.Item) lights.Add(blockInfo^.Item)
else else
x := blockInfo^.Item.X - ALeft; x := blockInfo^.Item.X - ALeft;
y := blockInfo^.Item.Y - ATop; y := blockInfo^.Item.Y - ATop;
if InRange(x, 0, AWidth - 1) and InRange(y, 0, AHeight - 1) then if InRange(x, 0, AWidth - 1) and InRange(y, 0, AHeight - 1) then
tileMap[x, y] := blockInfo^.Item; tileMap[x, y] := blockInfo^.Item;
end;
end; end;
end;
for i := 0 to lights.Count - 1 do for i := 0 to lights.Count - 1 do
begin begin
x := lights[i].X + 1 - ALeft; x := lights[i].X + 1 - ALeft;
y := lights[i].Y + 1 - ATop; y := lights[i].Y + 1 - ATop;
if (x = AWidth) or (y = AHeight) or if (x = AWidth) or (y = AHeight) or
(InRange(x, 0, AWidth - 1) and InRange(y, 0, AHeight - 1) and (InRange(x, 0, AWidth - 1) and InRange(y, 0, AHeight - 1) and
((tileMap[x,y] = nil) or (tileMap[x,y].Z < lights[i].Z + 5))) then ((tileMap[x,y] = nil) or (tileMap[x,y].Z < lights[i].Z + 5))) then
FLightSources.Add(TLightSource.Create(Self, lights[i])); FLightSources.Add(TLightSource.Create(Self, lights[i]));
end;
finally
lights.Free;
end; end;
lights.Free;
FValid := False; FValid := False;
//Logger.ExitMethod([lcClient, lcDebug], 'UpdateLightMap'); //Logger.ExitMethod([lcClient, lcDebug], 'UpdateLightMap');
end; end;