diff options
author | lukaslw | 2014-05-23 00:22:31 +0200 |
---|---|---|
committer | lukaslw | 2014-06-22 20:08:11 +0200 |
commit | e366a21f18eaf42ed0ff3eab56dc91183842ca53 (patch) | |
tree | cf86f5b7ca1f04b5131ee62ffed86891b25e2da3 | |
parent | 277ac367613d166a057c394f2033ab9a54c5206f (diff) | |
download | scummvm-rg350-e366a21f18eaf42ed0ff3eab56dc91183842ca53.tar.gz scummvm-rg350-e366a21f18eaf42ed0ff3eab56dc91183842ca53.tar.bz2 scummvm-rg350-e366a21f18eaf42ed0ff3eab56dc91183842ca53.zip |
PRINCE: Memory leak fixes, backAnimList clearing in new location
-rw-r--r-- | engines/prince/prince.cpp | 34 | ||||
-rw-r--r-- | engines/prince/script.cpp | 90 | ||||
-rw-r--r-- | engines/prince/script.h | 1 |
3 files changed, 75 insertions, 50 deletions
diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp index 124aed12ef..a575d15820 100644 --- a/engines/prince/prince.cpp +++ b/engines/prince/prince.cpp @@ -115,6 +115,12 @@ PrinceEngine::~PrinceEngine() { } _objList.clear(); + for (uint32 i = 0; i < _backAnimList.size(); i++) { + delete _backAnimList[i]._animData; + delete _backAnimList[i]._shadowData; + } + _backAnimList.clear(); + for (uint i = 0; i < _mainHero->_moveSet.size(); i++) { delete _mainHero->_moveSet[i]; } @@ -317,6 +323,11 @@ bool PrinceEngine::loadLocation(uint16 locationNr) { _mainHero->setShadowScale(_script->getShadowScale(_locationNr)); _room->loadRoom(_script->getRoomOffset(_locationNr)); + for (uint32 i = 0; i < _backAnimList.size(); i++) { + delete _backAnimList[i]._animData; + delete _backAnimList[i]._shadowData; + } + _backAnimList.clear(); _script->installBackAnims(_backAnimList, _room->_backAnim); _graph->makeShadowTable(70, _graph->_shadowTable70); @@ -475,24 +486,33 @@ bool PrinceEngine::loadShadow(byte *shadowBitmap, uint32 dataSize, const char *r Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(resourceName1); if (!stream) { + delete stream; return false; } if (stream->read(shadowBitmap, dataSize) != dataSize) { free(shadowBitmap); + delete stream; return false; } - stream = SearchMan.createReadStreamForMember(resourceName2); - if (!stream) { + Common::SeekableReadStream *stream2 = SearchMan.createReadStreamForMember(resourceName2); + if (!stream2) { + delete stream; + delete stream2; return false; } byte *shadowBitmap2 = shadowBitmap + dataSize; - if (stream->read(shadowBitmap2, dataSize) != dataSize) { + if (stream2->read(shadowBitmap2, dataSize) != dataSize) { free(shadowBitmap); + delete stream; + delete stream2; return false; } + + delete stream; + delete stream2; return true; } @@ -700,7 +720,6 @@ void PrinceEngine::drawScreen() { delete mainHeroSurface; } - playNextFrame(); /* if (!_objList.empty()) { for (int i = 0; i < _objList.size(); i++) { @@ -709,9 +728,14 @@ void PrinceEngine::drawScreen() { } */ for (int i = 0; i < _backAnimList.size() ; i++) { - _graph->drawTransparent(_backAnimList[i]._x, _backAnimList[i]._y, _backAnimList[i]._animData->getFrame(testAnimFrame)); + Graphics::Surface *backAnimSurface = _backAnimList[i]._animData->getFrame(testAnimFrame); + _graph->drawTransparent(_backAnimList[i]._x, _backAnimList[i]._y, backAnimSurface); // out of range now - crash .exe + backAnimSurface->free(); + delete backAnimSurface; } + playNextFrame(); + hotspot(); showTexts(); diff --git a/engines/prince/script.cpp b/engines/prince/script.cpp index 2b05e073f7..0dae2b1b5b 100644 --- a/engines/prince/script.cpp +++ b/engines/prince/script.cpp @@ -47,7 +47,6 @@ bool Room::loadRoom(byte *roomData) { _mobs = roomStream.readSint32LE(); _backAnim = roomStream.readSint32LE(); - debug("%d", _backAnim); _obj = roomStream.readSint32LE(); _nak = roomStream.readSint32LE(); _itemUse = roomStream.readSint32LE(); @@ -206,52 +205,53 @@ uint8 *Script::getRoomOffset(int locationNr) { return &_data[_scriptInfo.rooms + locationNr * 64]; } +void Script::installSingleBackAnim(Common::Array<Anim> &_backanimList, int offset) { + int animOffset = READ_UINT32(&_data[offset]); + int animNumber = READ_UINT16(&_data[animOffset + 28]); + Anim newAnim; + if (animOffset != 0) { + const Common::String animName = Common::String::format("AN%02d", animNumber); + const Common::String shadowName = Common::String::format("AN%02dS", animNumber); + newAnim._animData = new Animation(); + newAnim._shadowData = new Animation(); + Resource::loadResource(newAnim._animData, animName.c_str(), true); + if (!Resource::loadResource(newAnim._shadowData, shadowName.c_str(), false)) { + delete newAnim._shadowData; + newAnim._shadowData = nullptr; + } + newAnim._seq = 0; + newAnim._usage = 0; + newAnim._state = 0; // enabled + if ((_vm->_animList[animNumber]._flags & 4) != 0) { + newAnim._state = 1; + newAnim._frame = _vm->_animList[animNumber]._endPhase; + newAnim._showFrame = _vm->_animList[animNumber]._endPhase; + } else { + newAnim._frame = _vm->_animList[animNumber]._startPhase; + newAnim._showFrame = _vm->_animList[animNumber]._startPhase; + } + newAnim._flags = _vm->_animList[animNumber]._flags; + newAnim._lastFrame = _vm->_animList[animNumber]._endPhase; + newAnim._loopFrame = _vm->_animList[animNumber]._loopPhase; + newAnim._loopType = _vm->_animList[animNumber]._loopType; + newAnim._nextAnim = _vm->_animList[animNumber]._nextAnim; + newAnim._x = _vm->_animList[animNumber]._x; + newAnim._y = _vm->_animList[animNumber]._y; + newAnim._currFrame = 0; + newAnim._currX = _vm->_animList[animNumber]._x; + newAnim._currY = _vm->_animList[animNumber]._y; + newAnim._currW = 0; + newAnim._currH = 0; + newAnim._packFlag = 0; + newAnim._shadowBack = _vm->_animList[animNumber]._type; + _backanimList.push_back(newAnim); + //debug("animNo: %d", animNumber); + } +} + void Script::installBackAnims(Common::Array<Anim> &_backanimList, int offset) { for (uint i = 0; i < 64; i++) { - int animOffset = READ_UINT32(&_data[offset]); - int animNumber = READ_UINT16(&_data[animOffset + 28]); - Anim newAnim; - if (animOffset != 0) { - const Common::String animName = Common::String::format("AN%02d", animNumber); - const Common::String shadowName = Common::String::format("AN%02dS", animNumber, false); - newAnim._animData = new Animation(); - newAnim._shadowData = new Animation(); - Resource::loadResource(newAnim._animData, animName.c_str(), true); - if (!Resource::loadResource(newAnim._shadowData, shadowName.c_str(), false)) { - newAnim._shadowData = nullptr; - } - newAnim._seq = 0; - newAnim._usage = 0; - newAnim._state = 0; // enabled - if ((_vm->_animList[animNumber]._flags & 4) != 0) { - newAnim._state = 1; - newAnim._frame = _vm->_animList[animNumber]._endPhase; - newAnim._showFrame = _vm->_animList[animNumber]._endPhase; - } else { - newAnim._frame = _vm->_animList[animNumber]._startPhase; - newAnim._showFrame = _vm->_animList[animNumber]._startPhase; - } - newAnim._flags = _vm->_animList[animNumber]._flags; - newAnim._lastFrame = _vm->_animList[animNumber]._endPhase; - newAnim._loopFrame = _vm->_animList[animNumber]._loopPhase; - newAnim._loopType = _vm->_animList[animNumber]._loopType; - newAnim._nextAnim = _vm->_animList[animNumber]._nextAnim; - newAnim._x = _vm->_animList[animNumber]._x; - newAnim._y = _vm->_animList[animNumber]._y; - newAnim._currFrame = 0; - newAnim._currX = _vm->_animList[animNumber]._x; - newAnim._currY = _vm->_animList[animNumber]._y; - newAnim._currW = 0; - newAnim._currH = 0; - newAnim._packFlag = 0; - //newAnim._currShadowFrame = - //newAnim._packShadowFlag = - newAnim._shadowBack = _vm->_animList[animNumber]._type; - //newAnim._relX = - //newAnim._relY = - _backanimList.push_back(newAnim); - debug("animNo: %d", animNumber); - } + installSingleBackAnim(_backanimList, offset); offset += 4; } } diff --git a/engines/prince/script.h b/engines/prince/script.h index 31da31dffd..b2087c7b12 100644 --- a/engines/prince/script.h +++ b/engines/prince/script.h @@ -133,6 +133,7 @@ public: int32 getShadowScale(int locationNr); uint8 *getRoomOffset(int locationNr); void installBackAnims(Common::Array<Anim> &_backanimList, int offset); + void installSingleBackAnim(Common::Array<Anim> &_backanimList, int offset); const char *getString(uint32 offset) { return (const char *)(&_data[offset]); |