diff options
author | Colin Snover | 2017-11-16 12:05:14 -0600 |
---|---|---|
committer | Eugene Sandulenko | 2017-11-18 22:35:12 +0100 |
commit | 4cc64c4139903c9a6b769855ab2a8a8125beb644 (patch) | |
tree | 46c1076163f3dfa7bd913b2f39b7b0737487aa5c /engines | |
parent | a2e2569347794ee2c54bfac3b64076b481f50fd6 (diff) | |
download | scummvm-rg350-4cc64c4139903c9a6b769855ab2a8a8125beb644.tar.gz scummvm-rg350-4cc64c4139903c9a6b769855ab2a8a8125beb644.tar.bz2 scummvm-rg350-4cc64c4139903c9a6b769855ab2a8a8125beb644.zip |
FULLPIPE: Fix memory leaks in PictureObject, Background
Diffstat (limited to 'engines')
-rw-r--r-- | engines/fullpipe/gfx.cpp | 56 | ||||
-rw-r--r-- | engines/fullpipe/gfx.h | 30 | ||||
-rw-r--r-- | engines/fullpipe/init.cpp | 2 | ||||
-rw-r--r-- | engines/fullpipe/inventory.cpp | 2 | ||||
-rw-r--r-- | engines/fullpipe/modal.cpp | 4 | ||||
-rw-r--r-- | engines/fullpipe/scene.cpp | 20 | ||||
-rw-r--r-- | engines/fullpipe/scene.h | 2 |
7 files changed, 44 insertions, 72 deletions
diff --git a/engines/fullpipe/gfx.cpp b/engines/fullpipe/gfx.cpp index ae2ddace22..a2626e28ea 100644 --- a/engines/fullpipe/gfx.cpp +++ b/engines/fullpipe/gfx.cpp @@ -38,22 +38,11 @@ Background::Background() { _x = 0; _y = 0; _messageQueueId = 0; - _bigPictureArray1Count = 0; - _bigPictureArray2Count = 0; - _bigPictureArray = 0; } Background::~Background() { - _picObjList.clear(); - - for (int i = 0; i < _bigPictureArray1Count; i++) { - for (int j = 0; j < _bigPictureArray2Count; j++) - delete _bigPictureArray[i][j]; - - free(_bigPictureArray[i]); - } - - free(_bigPictureArray); + Common::for_each(_picObjList.begin(), _picObjList.end(), Common::DefaultDeleter<PictureObject>()); + Common::for_each(_bigPictureArray.begin(), _bigPictureArray.end(), Common::DefaultDeleter<BigPicture>()); } bool Background::load(MfcArchive &file) { @@ -69,25 +58,16 @@ bool Background::load(MfcArchive &file) { addPictureObject(pct); } - assert(g_fp->_gameProjectVersion >= 4); - - _bigPictureArray1Count = file.readUint32LE(); - assert(g_fp->_gameProjectVersion >= 5); - _bigPictureArray2Count = file.readUint32LE(); - - _bigPictureArray = (BigPicture ***)calloc(_bigPictureArray1Count, sizeof(BigPicture **)); + _bigPictureXDim = file.readUint32LE(); + _bigPictureYDim = file.readUint32LE(); - debugC(6, kDebugLoading, "bigPictureArray[%d][%d]", _bigPictureArray1Count, _bigPictureArray2Count); + debugC(6, kDebugLoading, "bigPictureArray[%d][%d]", _bigPictureXDim, _bigPictureYDim); - for (int i = 0; i < _bigPictureArray1Count; i++) { - _bigPictureArray[i] = (BigPicture **)calloc(_bigPictureArray2Count, sizeof(BigPicture *)); - for (int j = 0; j < _bigPictureArray2Count; j++) { - _bigPictureArray[i][j] = new BigPicture(); - - _bigPictureArray[i][j]->load(file); - } + for (uint i = 0; i < _bigPictureXDim * _bigPictureYDim; ++i) { + _bigPictureArray.push_back(new BigPicture()); + _bigPictureArray[i]->load(file); } return true; @@ -114,19 +94,11 @@ void Background::addPictureObject(PictureObject *pct) { PictureObject::PictureObject() { _ox = 0; _oy = 0; - _picture = 0; _ox2 = 0; _oy2 = 0; - _pictureObject2List = 0; _objtype = kObjTypePictureObject; } -PictureObject::~PictureObject() { - delete _picture; - _pictureObject2List->clear(); - delete _pictureObject2List; -} - PictureObject::PictureObject(PictureObject *src) : GameObject(src) { _picture = src->_picture; _ox2 = _ox; @@ -140,21 +112,17 @@ bool PictureObject::load(MfcArchive &file, bool bigPicture) { GameObject::load(file); if (bigPicture) - _picture = new BigPicture(); + _picture = Common::SharedPtr<Picture>(new BigPicture()); else - _picture = new Picture(); + _picture = Common::SharedPtr<Picture>(new Picture()); _picture->load(file); - _pictureObject2List = new Common::Array<GameObject *>; - int count = file.readUint16LE(); if (count > 0) { - GameObject *o = new GameObject(); - - o->load(file); - _pictureObject2List->push_back(o); + _pictureObject2List.push_back(GameObject()); + _pictureObject2List.back().load(file); } _ox2 = _ox; diff --git a/engines/fullpipe/gfx.h b/engines/fullpipe/gfx.h index 252f855691..a7c0c765e2 100644 --- a/engines/fullpipe/gfx.h +++ b/engines/fullpipe/gfx.h @@ -167,17 +167,10 @@ class GameObject : public CObject { }; class PictureObject : public GameObject { - public: - Picture *_picture; - Common::Array<GameObject *> *_pictureObject2List; - int _ox2; - int _oy2; - - public: +public: PictureObject(); PictureObject(PictureObject *src); - virtual ~PictureObject(); virtual bool load(MfcArchive &file, bool bigPicture); virtual bool load(MfcArchive &file) { assert(0); return false; } // Disable base class @@ -190,10 +183,18 @@ class PictureObject : public GameObject { bool isPointInside(int x, int y); bool isPixelHitAtPos(int x, int y); void setOXY2(); + + Common::SharedPtr<Picture> _picture; + +private: + Common::Array<GameObject> _pictureObject2List; + int _ox2; + int _oy2; }; class Background : public CObject { - public: +public: + /** list items are owned */ Common::Array<PictureObject *> _picObjList; Common::String _bgname; @@ -201,18 +202,19 @@ class Background : public CObject { int _y; int16 _messageQueueId; Palette _palette; - int _bigPictureArray1Count; - int _bigPictureArray2Count; - BigPicture ***_bigPictureArray; + /** list items are owned */ + Common::Array<BigPicture *> _bigPictureArray; + uint _bigPictureXDim; + uint _bigPictureYDim; - public: +public: Background(); virtual ~Background(); virtual bool load(MfcArchive &file); void addPictureObject(PictureObject *pct); - BigPicture *getBigPicture(int x, int y) { return _bigPictureArray[x][y]; } + BigPicture *getBigPicture(int x, int y) { return _bigPictureArray[y * _bigPictureYDim + x]; } }; struct ShadowsItem { diff --git a/engines/fullpipe/init.cpp b/engines/fullpipe/init.cpp index db95cd88b8..d49d956097 100644 --- a/engines/fullpipe/init.cpp +++ b/engines/fullpipe/init.cpp @@ -144,7 +144,7 @@ void FullpipeEngine::setLevelStates() { void FullpipeEngine::addCursor(CursorInfo *cursorInfo, Scene *inv, int pictureId, int hotspotX, int hotspotY, int itemPictureOffsX, int itemPictureOffsY) { cursorInfo->pictureId = pictureId; - cursorInfo->picture = inv->getPictureObjectById(pictureId, 0)->_picture; + cursorInfo->picture = inv->getPictureObjectById(pictureId, 0)->_picture.get(); cursorInfo->hotspotX = hotspotX; cursorInfo->hotspotY = hotspotY; cursorInfo->itemPictureOffsX = itemPictureOffsX; diff --git a/engines/fullpipe/inventory.cpp b/engines/fullpipe/inventory.cpp index cb9eec75c3..952b359d19 100644 --- a/engines/fullpipe/inventory.cpp +++ b/engines/fullpipe/inventory.cpp @@ -427,7 +427,7 @@ int Inventory2::selectItem(int itemId) { if (_scene) { int idx = getInventoryPoolItemIndexById(itemId); - Picture *pic = _scene->getPictureObjectById(_itemsPool[idx]->pictureObjectId1, 0)->_picture; + Picture *pic = _scene->getPictureObjectById(_itemsPool[idx]->pictureObjectId1, 0)->_picture.get(); g_fp->getGameLoaderInputController()->setCursorItemPicture(pic); } diff --git a/engines/fullpipe/modal.cpp b/engines/fullpipe/modal.cpp index f07fb9a1b8..0f9877a0af 100644 --- a/engines/fullpipe/modal.cpp +++ b/engines/fullpipe/modal.cpp @@ -1796,9 +1796,9 @@ void ModalHelp::launch() { if (_mainMenuScene) { if (g_fp->isDemo() && g_fp->getLanguage() == Common::RU_RUS) - _bg = _mainMenuScene->getPictureObjectById(364, 0)->_picture; + _bg = _mainMenuScene->getPictureObjectById(364, 0)->_picture.get(); else - _bg = _mainMenuScene->getPictureObjectById(PIC_HLP_BGR, 0)->_picture; + _bg = _mainMenuScene->getPictureObjectById(PIC_HLP_BGR, 0)->_picture.get(); _isRunning = 1; } } diff --git a/engines/fullpipe/scene.cpp b/engines/fullpipe/scene.cpp index 69ab170e4d..d4da322b40 100644 --- a/engines/fullpipe/scene.cpp +++ b/engines/fullpipe/scene.cpp @@ -655,7 +655,7 @@ void Scene::update(int counterdiff) { } void Scene::drawContent(int minPri, int maxPri, bool drawBg) { - if (!_picObjList.size() && !_bigPictureArray1Count) + if (!_picObjList.size() && !_bigPictureXDim) return; if (_palette.size()) { @@ -682,11 +682,11 @@ void Scene::drawContent(int minPri, int maxPri, bool drawBg) { Dims dims; - debugC(1, kDebugDrawing, "_bigPict: %d objlist: %d", _bigPictureArray1Count, _picObjList.size()); + debugC(1, kDebugDrawing, "_bigPict: %d objlist: %d", _bigPictureXDim, _picObjList.size()); - if (drawBg && _bigPictureArray1Count && _picObjList.size()) { + if (drawBg && _bigPictureXDim && _picObjList.size()) { - dims = _bigPictureArray[0][0]->getDimensions(); + dims = _bigPictureArray[0]->getDimensions(); int width = dims.x; int height = dims.y; @@ -716,26 +716,26 @@ void Scene::drawContent(int minPri, int maxPri, bool drawBg) { int bgPosX = g_fp->_sceneRect.left - bgOffsetX; if (bgPosX < g_fp->_sceneRect.right - 1) { - while (1) { - int v25 = bgNumY; + for (;;) { + uint v25 = bgNumY; for (int y = g_fp->_sceneRect.top - bgOffsetY; y < g_fp->_sceneRect.bottom - 1;) { - BigPicture *v27 = _bigPictureArray[bgNumX][v25]; + BigPicture *v27 = getBigPicture(bgNumX, v25); v27->draw(bgPosX, y, 0, 0); y += v27->getDimensions().y; v25++; - if (v25 >= _bigPictureArray2Count) { + if (v25 >= _bigPictureYDim) { if (!(_picObjList[0]->_flags & 0x20)) break; v25 = 0; } } - dims = _bigPictureArray[bgNumX][0]->getDimensions(); + dims = getBigPicture(bgNumX, 0)->getDimensions(); int oldx = dims.x + bgPosX; bgPosX += dims.x; bgNumX++; - if (bgNumX >= _bigPictureArray1Count) { + if (bgNumX >= (int)_bigPictureXDim) { if (!(_picObjList[0]->_flags & 0x2)) break; bgNumX = 0; diff --git a/engines/fullpipe/scene.h b/engines/fullpipe/scene.h index cc4cf17d64..97e654d119 100644 --- a/engines/fullpipe/scene.h +++ b/engines/fullpipe/scene.h @@ -32,7 +32,9 @@ class MessageQueue; class Scene : public Background { public: + /** list items are owned */ Common::Array<StaticANIObject *> _staticANIObjectList1; + Common::Array<StaticANIObject *> _staticANIObjectList2; Common::Array<MessageQueue *> _messageQueueList; // PtrList _faObjectList; // not used |