🚨 Make radar shutdown safe

Destroying the radar window dereferenced the image without a nil
check when creation had failed, and leaked the cache file stream on
write errors, skipping cleanup of the remaining objects.
This commit is contained in:
2026-11-15 22:08:32 +01:00
parent 93c2af9d9f
commit 71865facd8
+20 -11
View File
@@ -110,18 +110,27 @@ var
begin begin
RegisterPacketHandler($0D, nil); RegisterPacketHandler($0D, nil);
SetLength(radarMap, FRadar.Width * FRadar.Height);
for x := 0 to FRadar.Width - 1 do
for y := 0 to FRadar.Height - 1 do
radarMap[x * FRadar.Height + y] := EncodeUOColor(PInteger(FRadar.PixelPointer[x, y])^);
radarMapFile := TFileStream.Create(GetAppConfigDir(False) + 'RadarMap.cache',
fmCreate);
radarMapFile.Write(radarMap[0], Length(radarMap) * SizeOf(Word));
radarMapFile.Free;
if FRadarDependencies <> nil then FreeAndNil(FRadarDependencies); if FRadarDependencies <> nil then FreeAndNil(FRadarDependencies);
if FRadar <> nil then FreeAndNil(FRadar);
if FRadar <> nil then
begin
SetLength(radarMap, FRadar.Width * FRadar.Height);
if Length(radarMap) > 0 then
begin
for x := 0 to FRadar.Width - 1 do
for y := 0 to FRadar.Height - 1 do
radarMap[x * FRadar.Height + y] := EncodeUOColor(PInteger(FRadar.PixelPointer[x, y])^);
radarMapFile := TFileStream.Create(GetAppConfigDir(False) + 'RadarMap.cache',
fmCreate);
try
radarMapFile.Write(radarMap[0], Length(radarMap) * SizeOf(Word));
finally
radarMapFile.Free;
end;
end;
FreeAndNil(FRadar);
end;
end; end;
procedure TfrmRadarMap.FormResize(Sender: TObject); procedure TfrmRadarMap.FormResize(Sender: TObject);