mirror of
https://github.com/libretro/scummvm.git
synced 2025-04-02 06:41:51 +00:00
PRINCE: Memory leak fixes, backAnimList clearing in new location
This commit is contained in:
parent
277ac36761
commit
e366a21f18
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user