🚨 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:
+20
-11
@@ -110,18 +110,27 @@ var
|
||||
begin
|
||||
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 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;
|
||||
|
||||
procedure TfrmRadarMap.FormResize(Sender: TObject);
|
||||
|
||||
Reference in New Issue
Block a user