diff options
author | WinterGrascph | 2016-05-17 22:56:14 +0200 |
---|---|---|
committer | Bendegúz Nagy | 2016-08-26 23:02:22 +0200 |
commit | 7ddd96bc60e9a5cbe33a5a246f5a8709d4948181 (patch) | |
tree | 093ee5edd5b5985bee3fce1863e9a11bf1f2efc3 /engines | |
parent | 909ec36edf6206efac5d2b4bea32a019520087b7 (diff) | |
download | scummvm-rg350-7ddd96bc60e9a5cbe33a5a246f5a8709d4948181.tar.gz scummvm-rg350-7ddd96bc60e9a5cbe33a5a246f5a8709d4948181.tar.bz2 scummvm-rg350-7ddd96bc60e9a5cbe33a5a246f5a8709d4948181.zip |
DM: Fix destructor and allocation issues in DungeonMan and DisplayMan
Diffstat (limited to 'engines')
-rw-r--r-- | engines/dm/dungeonman.cpp | 20 | ||||
-rw-r--r-- | engines/dm/gfx.cpp | 61 |
2 files changed, 41 insertions, 40 deletions
diff --git a/engines/dm/dungeonman.cpp b/engines/dm/dungeonman.cpp index e6d94ec07d..2d700f3d89 100644 --- a/engines/dm/dungeonman.cpp +++ b/engines/dm/dungeonman.cpp @@ -84,7 +84,7 @@ void DungeonMan::decompressDungeonFile() { f.open("Dungeon.dat"); if (f.readUint16BE() == 0x8104) { _rawDunFileDataSize = f.readUint32BE(); - if (_rawDunFileData) delete[] _rawDunFileData; + delete[] _rawDunFileData; _rawDunFileData = new byte[_rawDunFileDataSize]; f.readUint16BE(); byte common[4]; @@ -209,8 +209,7 @@ void DungeonMan::loadDungeonFile() { } // load map data - if (_maps) delete[] _maps; - + delete[] _maps; _maps = new Map[_fileHeader.mapCount]; for (uint16 i = 0; i < _fileHeader.mapCount; ++i) { _maps[i].rawDunDataOffset = dunDataStream.readUint16BE(); @@ -242,8 +241,7 @@ void DungeonMan::loadDungeonFile() { } // TODO: ??? is this - begin - if (_dunData.mapsFirstColumnIndex) delete[] _dunData.mapsFirstColumnIndex; - + delete[] _dunData.mapsFirstColumnIndex; _dunData.mapsFirstColumnIndex = new uint16[_fileHeader.mapCount]; uint16 columCount = 0; for (uint16 i = 0; i < _fileHeader.mapCount; ++i) { @@ -259,16 +257,14 @@ void DungeonMan::loadDungeonFile() { _fileHeader.squareFirstThingCount += 300; // TODO: ??? is this - begin - if (_dunData.columnsCumulativeSquareThingCount) - delete[] _dunData.columnsCumulativeSquareThingCount; + delete[] _dunData.columnsCumulativeSquareThingCount; _dunData.columnsCumulativeSquareThingCount = new uint16[columCount]; for (uint16 i = 0; i < columCount; ++i) _dunData.columnsCumulativeSquareThingCount[i] = dunDataStream.readUint16BE(); // TODO: ??? is this - end // TODO: ??? is this - begin - if (_dunData.squareFirstThings) - delete[] _dunData.squareFirstThings; + delete[] _dunData.squareFirstThings; _dunData.squareFirstThings = new Thing[_fileHeader.squareFirstThingCount]; for (uint16 i = 0; i < actualSquareFirstThingCount; ++i) _dunData.squareFirstThings[i].set(dunDataStream.readUint16BE()); @@ -279,8 +275,7 @@ void DungeonMan::loadDungeonFile() { // TODO: ??? is this - end // load text data - if (_dunData.textData) - delete[] _dunData.textData; + delete[] _dunData.textData; _dunData.textData = new uint16[_fileHeader.textDataWordCount]; for (uint16 i = 0; i < _fileHeader.textDataWordCount; ++i) _dunData.textData[i] = dunDataStream.readUint16BE(); @@ -348,8 +343,7 @@ void DungeonMan::loadDungeonFile() { if (!_messages.restartGameRequest) { uint8 mapCount = _fileHeader.mapCount; - if (_dunData.mapData) - delete[] _dunData.mapData; + delete[] _dunData.mapData; _dunData.mapData = new byte**[_dunData.columCount + mapCount]; byte **colFirstSquares = (byte**)_dunData.mapData + mapCount; for (uint8 i = 0; i < mapCount; ++i) { diff --git a/engines/dm/gfx.cpp b/engines/dm/gfx.cpp index ae5bcd9f88..3a9d1f03ba 100644 --- a/engines/dm/gfx.cpp +++ b/engines/dm/gfx.cpp @@ -21,6 +21,25 @@ namespace DM { #define kFirstFloorOrn 247 // @ C247_GRAPHIC_FIRST_FLOOR_ORNAMENT #define kFirstDoorOrn 303 // @ C303_GRAPHIC_FIRST_DOOR_ORNAMENT +enum WallSetIndices { + kDoorFrameFront = 0, // @ G0709_puc_Bitmap_WallSet_DoorFrameFront + kDoorFrameLeft_D1C = 1, // @ G0708_puc_Bitmap_WallSet_DoorFrameLeft_D1C + kFameLeft_D2C = 2, // @ G0707_puc_Bitmap_WallSet_DoorFrameLeft_D2C + kDoorFrameLeft_D3C = 3, // @ G0706_puc_Bitmap_WallSet_DoorFrameLeft_D3C + kDoorFrameLeft_D3L = 4, // @ G0705_puc_Bitmap_WallSet_DoorFrameLeft_D3L + kDoorFrameTop_D1LCR = 5, // @ G0704_puc_Bitmap_WallSet_DoorFrameTop_D1LCR + kDoorFrameTop_D2LCR = 6, // @ G0703_puc_Bitmap_WallSet_DoorFrameTop_D2LCR + kWall_D0R = 7, // @ G0702_puc_Bitmap_WallSet_Wall_D0R + kWall_D0L = 8, // @ G0701_puc_Bitmap_WallSet_Wall_D0L + kWall_D1LCR = 9, // @ G0700_puc_Bitmap_WallSet_Wall_D1LCR + kWall_D2LCR = 10, // @ G0699_puc_Bitmap_WallSet_Wall_D2LCR + kWall_D3LCR = 11, // @ G0698_puc_Bitmap_WallSet_Wall_D3LCR + kWall_D3L2 = 12, // @ G0697_puc_Bitmap_WallSet_Wall_D3L2 + + kWall_D3R2 = 13, // @ G0696_puc_Bitmap_WallSet_Wall_D3R2 + kDoorFrameRight_D1C = 14// @ G0710_puc_Bitmap_WallSet_DoorFrameRight_D1C +}; + byte gDoorOrnCoordIndices[12] = { // @ G0196_auc_Graphic558_DoorOrnamentCoordinateSetIndices 0, /* Door Ornament #00 Square Grid */ @@ -496,15 +515,18 @@ DisplayMan::~DisplayMan() { delete[] _packedItemPos; delete[] _packedBitmaps; delete[] _vgaBuffer; - delete[] _bitmaps[0]; - delete[] _bitmaps; - delete[] _wallSetBitMaps[13]; // copy of another bitmap, but flipped - delete[] _wallSetBitMaps[14]; // copy of another bitmap, but flipped + if (_bitmaps) { + delete[] _bitmaps[0]; + delete[] _bitmaps; + } + delete[] _wallSetBitMaps[kWall_D3R2]; // copy of another bitmap, but flipped + delete[] _wallSetBitMaps[kDoorFrameRight_D1C]; // copy of another bitmap, but flipped } void DisplayMan::setUpScreens(uint16 width, uint16 height) { _screenWidth = width; _screenHeight = height; + delete[] _vgaBuffer; _vgaBuffer = new byte[_screenWidth * _screenHeight]; clearScreen(kColorBlack); } @@ -514,11 +536,13 @@ void DisplayMan::loadGraphics() { f.open("graphics.dat"); grapItemCount = f.readUint16BE(); + delete[] _packedItemPos; _packedItemPos = new uint32[grapItemCount + 1]; _packedItemPos[0] = 0; for (uint16 i = 1; i < grapItemCount + 1; ++i) _packedItemPos[i] = f.readUint16BE() + _packedItemPos[i - 1]; + delete[] _packedBitmaps; _packedBitmaps = new uint8[_packedItemPos[grapItemCount]]; f.seek(2 + grapItemCount * 4); @@ -553,6 +577,10 @@ void DisplayMan::unpackGraphics() { for (uint16 i = 22; i <= 532; ++i) unpackedBitmapsSize += width(i) * height(i); // graphics items go from 0-20 and 22-532 inclusive, _unpackedItemPos 21 and 22 are there for indexing convenience + if (_bitmaps) { + delete[] _bitmaps[0]; + delete[] _bitmaps; + } _bitmaps = new byte*[533]; _bitmaps[0] = new byte[unpackedBitmapsSize]; loadIntoBitmap(0, _bitmaps[0]); @@ -702,25 +730,6 @@ void DisplayMan::drawSquareD3L(direction dir, int16 posX, int16 posY) { } -enum WallSetIndices { - kDoorFrameFront = 0, // @ G0709_puc_Bitmap_WallSet_DoorFrameFront - kDoorFrameLeft_D1C = 1, // @ G0708_puc_Bitmap_WallSet_DoorFrameLeft_D1C - kFameLeft_D2C = 2, // @ G0707_puc_Bitmap_WallSet_DoorFrameLeft_D2C - kDoorFrameLeft_D3C = 3, // @ G0706_puc_Bitmap_WallSet_DoorFrameLeft_D3C - kDoorFrameLeft_D3L = 4, // @ G0705_puc_Bitmap_WallSet_DoorFrameLeft_D3L - kDoorFrameTop_D1LCR = 5, // @ G0704_puc_Bitmap_WallSet_DoorFrameTop_D1LCR - kDoorFrameTop_D2LCR = 6, // @ G0703_puc_Bitmap_WallSet_DoorFrameTop_D2LCR - kWall_D0R = 7, // @ G0702_puc_Bitmap_WallSet_Wall_D0R - kWall_D0L = 8, // @ G0701_puc_Bitmap_WallSet_Wall_D0L - kWall_D1LCR = 9, // @ G0700_puc_Bitmap_WallSet_Wall_D1LCR - kWall_D2LCR = 10, // @ G0699_puc_Bitmap_WallSet_Wall_D2LCR - kWall_D3LCR = 11, // @ G0698_puc_Bitmap_WallSet_Wall_D3LCR - kWall_D3L2 = 12, // @ G0697_puc_Bitmap_WallSet_Wall_D3L2 - - kWall_D3R2 = 13, // @ G0696_puc_Bitmap_WallSet_Wall_D3R2 - kDoorFrameRight_D1C = 14// @ G0710_puc_Bitmap_WallSet_DoorFrameRight_D1C -}; - void DisplayMan::drawDungeon(direction dir, int16 posX, int16 posY) { loadPalette(gPalDungeonView[0]); // TODO: this is a global variable, set from here @@ -783,16 +792,14 @@ void DisplayMan::loadWallSet(WallSet set) { uint16 leftDoorIndice = firstIndice + kDoorFrameLeft_D1C; uint16 w = width(leftDoorIndice), h = height(leftDoorIndice); - if (_wallSetBitMaps[kDoorFrameRight_D1C]) - delete[] _wallSetBitMaps[kDoorFrameRight_D1C]; + delete[] _wallSetBitMaps[kDoorFrameRight_D1C]; _wallSetBitMaps[kDoorFrameRight_D1C] = new byte[w * h]; blitToBitmap(_wallSetBitMaps[kDoorFrameLeft_D1C], w, h, _wallSetBitMaps[kDoorFrameRight_D1C], w); flipBitmapHorizontal(_wallSetBitMaps[kDoorFrameRight_D1C], w, h); uint16 leftWallIndice = firstIndice + kWall_D3L2; w = width(leftWallIndice), h = height(leftWallIndice); - if (_wallSetBitMaps[kWall_D3R2]) - delete[] _wallSetBitMaps[kWall_D3R2]; + delete[] _wallSetBitMaps[kWall_D3R2]; _wallSetBitMaps[kWall_D3R2] = new byte[w * h]; blitToBitmap(_wallSetBitMaps[kWall_D3L2], w, h, _wallSetBitMaps[kWall_D3R2], w); flipBitmapHorizontal(_wallSetBitMaps[kWall_D3R2], w, h); |