🐛 Free the block parts when loading corrupt map data fails
A failed block creation leaked the already constructed halves and the index.
This commit is contained in:
+17
-7
@@ -538,15 +538,25 @@ var
|
|||||||
index: TGenericIndex;
|
index: TGenericIndex;
|
||||||
begin
|
begin
|
||||||
FMap.Position := ((AX * FHeight) + AY) * 196;
|
FMap.Position := ((AX * FHeight) + AY) * 196;
|
||||||
map := TMapBlock.Create(FMap, AX, AY);
|
map := nil;
|
||||||
|
statics := nil;
|
||||||
|
index := nil;
|
||||||
|
try
|
||||||
|
map := TMapBlock.Create(FMap, AX, AY);
|
||||||
|
|
||||||
FStaIdx.Position := ((AX * FHeight) + AY) * 12;
|
FStaIdx.Position := ((AX * FHeight) + AY) * 12;
|
||||||
index := TGenericIndex.Create(FStaIdx);
|
index := TGenericIndex.Create(FStaIdx);
|
||||||
statics := TSeperatedStaticBlock.Create(FStatics, index, AX, AY);
|
statics := TSeperatedStaticBlock.Create(FStatics, index, AX, AY);
|
||||||
statics.TiledataProvider := FTiledataProvider;
|
statics.TiledataProvider := FTiledataProvider;
|
||||||
index.Free;
|
index.Free;
|
||||||
|
|
||||||
Result := TBlock.Create(map, statics);
|
Result := TBlock.Create(map, statics);
|
||||||
|
except
|
||||||
|
map.Free;
|
||||||
|
statics.Free;
|
||||||
|
index.Free;
|
||||||
|
raise;
|
||||||
|
end;
|
||||||
FBlockCache.StoreID(GetID(AX, AY), Result);
|
FBlockCache.StoreID(GetID(AX, AY), Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user