🚨 Free the light collection when the light map update fails
This commit is contained in:
+33
-31
@@ -285,44 +285,46 @@ begin
|
||||
{Logger.Send([lcClient, lcDebug], 'AWidth', AWidth);
|
||||
Logger.Send([lcClient, lcDebug], 'AHeight', AHeight);}
|
||||
lights := TWorldItemList.Create(False);
|
||||
SetLength(tileMap, AWidth, AHeight);
|
||||
for x := 0 to AWidth - 1 do
|
||||
for y := 0 to AHeight - 1 do
|
||||
tileMap[x,y] := nil;
|
||||
try
|
||||
SetLength(tileMap, AWidth, AHeight);
|
||||
for x := 0 to AWidth - 1 do
|
||||
for y := 0 to AHeight - 1 do
|
||||
tileMap[x,y] := nil;
|
||||
|
||||
blockInfo := nil;
|
||||
while AScreenBuffer.Iterate(blockInfo) do
|
||||
begin
|
||||
if blockInfo^.State = ssNormal then
|
||||
blockInfo := nil;
|
||||
while AScreenBuffer.Iterate(blockInfo) do
|
||||
begin
|
||||
if blockInfo^.Item is TStaticItem then
|
||||
tileID := blockInfo^.Item.TileID + $4000
|
||||
else
|
||||
tileID := blockInfo^.Item.TileID;
|
||||
tileData := ResMan.Tiledata.TileData[tileID];
|
||||
if blockInfo^.State = ssNormal then
|
||||
begin
|
||||
if blockInfo^.Item is TStaticItem then
|
||||
tileID := blockInfo^.Item.TileID + $4000
|
||||
else
|
||||
tileID := blockInfo^.Item.TileID;
|
||||
tileData := ResMan.Tiledata.TileData[tileID];
|
||||
|
||||
if tdfLightSource in tileData.Flags then
|
||||
lights.Add(blockInfo^.Item)
|
||||
else
|
||||
x := blockInfo^.Item.X - ALeft;
|
||||
y := blockInfo^.Item.Y - ATop;
|
||||
if InRange(x, 0, AWidth - 1) and InRange(y, 0, AHeight - 1) then
|
||||
tileMap[x, y] := blockInfo^.Item;
|
||||
if tdfLightSource in tileData.Flags then
|
||||
lights.Add(blockInfo^.Item)
|
||||
else
|
||||
x := blockInfo^.Item.X - ALeft;
|
||||
y := blockInfo^.Item.Y - ATop;
|
||||
if InRange(x, 0, AWidth - 1) and InRange(y, 0, AHeight - 1) then
|
||||
tileMap[x, y] := blockInfo^.Item;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
for i := 0 to lights.Count - 1 do
|
||||
begin
|
||||
x := lights[i].X + 1 - ALeft;
|
||||
y := lights[i].Y + 1 - ATop;
|
||||
if (x = AWidth) or (y = AHeight) or
|
||||
(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
|
||||
FLightSources.Add(TLightSource.Create(Self, lights[i]));
|
||||
for i := 0 to lights.Count - 1 do
|
||||
begin
|
||||
x := lights[i].X + 1 - ALeft;
|
||||
y := lights[i].Y + 1 - ATop;
|
||||
if (x = AWidth) or (y = AHeight) or
|
||||
(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
|
||||
FLightSources.Add(TLightSource.Create(Self, lights[i]));
|
||||
end;
|
||||
finally
|
||||
lights.Free;
|
||||
end;
|
||||
|
||||
lights.Free;
|
||||
|
||||
FValid := False;
|
||||
//Logger.ExitMethod([lcClient, lcDebug], 'UpdateLightMap');
|
||||
end;
|
||||
|
||||
Reference in New Issue
Block a user