SAGA2: Create destructors for MapHeader and MetaTileList

This commit is contained in:
a/ 2021-06-17 16:55:55 +09:00 committed by Eugene Sandulenko
parent f930e14188
commit ed2fe2befc
No known key found for this signature in database
GPG Key ID: 014D387312D34F08
2 changed files with 21 additions and 14 deletions

View File

@ -1442,6 +1442,11 @@ MapHeader::MapHeader(Common::SeekableReadStream *stream) {
mapData[i] = stream->readUint16LE();
}
MapHeader::~MapHeader() {
if (mapData)
delete[] mapData;
}
MetaTile::MetaTile(int ind, Common::SeekableReadStream *stream) {
_index = ind;
_highestPixel = stream->readUint16LE();
@ -1462,6 +1467,17 @@ MetaTileList::MetaTileList(int count, Common::SeekableReadStream *stream) {
}
}
MetaTileList::~MetaTileList() {
if (_tiles) {
for (int i = 0; i < _count; ++i) {
if (_tiles[i])
delete _tiles[i];
}
free(_tiles);
}
}
static void readActiveItem(hResContext *con, ActiveItem &itm) {
// FIXME: 32-bit pointer to 64-bit pointer conversion.
// Is this dangerous?
@ -1627,23 +1643,12 @@ void cleanupMaps(void) {
WorldMapData *mapData = &mapList[i];
// Dump the map
if (mapData->map != nullptr) {
if (mapData->map->mapData != nullptr)
delete[] mapData->map->mapData;
if (mapData->map != nullptr)
delete mapData->map;
mapData->map = nullptr;
}
// Dump the meta tile list
if (mapData->metaList) {
for (int k = 0; k < mapData->metaList->_count; ++i)
if (mapData->metaList->_tiles[i])
delete mapData->metaList->_tiles[i];
free(mapData->metaList->_tiles);
}
delete mapData->metaList;
if (mapData->metaList)
delete mapData->metaList;
// If there is active item data, dump it
if (mapData->activeItemData != nullptr)

View File

@ -825,6 +825,7 @@ public:
MetaTile **_tiles;
MetaTileList(int count, Common::SeekableReadStream *stream);
~MetaTileList();
};
/* ===================================================================== *
@ -837,6 +838,7 @@ struct MapHeader {
uint16 *mapData; // start of map array
MapHeader(Common::SeekableReadStream *stream);
~MapHeader();
};
enum mapEdgeTypes {