PRINCE: Memory leaks fix - showBackAnim(), printAt(), checkMob()"

This commit is contained in:
lukaslw 2014-06-29 20:39:40 +02:00
parent 7ebcbea0f9
commit 191b4cc8be
7 changed files with 29 additions and 17 deletions

View file

@ -46,6 +46,8 @@ GraphicsMan::GraphicsMan(PrinceEngine *vm)
GraphicsMan::~GraphicsMan() { GraphicsMan::~GraphicsMan() {
_frontScreen->free(); _frontScreen->free();
delete _frontScreen; delete _frontScreen;
_screenForInventory->free();
delete _screenForInventory;
delete[] _shadowTable70; delete[] _shadowTable70;
delete[] _shadowTable50; delete[] _shadowTable50;
} }

View file

@ -140,6 +140,8 @@ PrinceEngine::~PrinceEngine() {
} }
_maskList.clear(); _maskList.clear();
freeDrawNodes();
clearBackAnimList(); clearBackAnimList();
for (uint i = 0; i < _allInvList.size(); i++) { for (uint i = 0; i < _allInvList.size(); i++) {
@ -404,6 +406,8 @@ bool PrinceEngine::loadLocation(uint16 locationNr) {
_mobList[i]._visible = _script->getMobVisible(i); _mobList[i]._visible = _script->getMobVisible(i);
} }
freeDrawNodes();
clearBackAnimList(); clearBackAnimList();
_script->installBackAnims(_backAnimList, _room->_backAnim); _script->installBackAnims(_backAnimList, _room->_backAnim);
@ -855,8 +859,10 @@ int PrinceEngine::checkMob(Graphics::Surface *screen, Common::Array<Mob> &mobLis
int phase = backAnim._showFrame; int phase = backAnim._showFrame;
int phaseFrameIndex = backAnim._animData->getPhaseFrameIndex(phase); int phaseFrameIndex = backAnim._animData->getPhaseFrameIndex(phase);
Graphics::Surface *backAnimSurface = backAnim._animData->getFrame(phaseFrameIndex); Graphics::Surface *backAnimSurface = backAnim._animData->getFrame(phaseFrameIndex);
byte *pixel = (byte *)backAnimSurface->getBasePtr(mousePosCamera.x - backAnim._currX, mousePosCamera.y - backAnim._currY); byte pixel = *(byte *)backAnimSurface->getBasePtr(mousePosCamera.x - backAnim._currX, mousePosCamera.y - backAnim._currY);
if (*pixel != 255) { backAnimSurface->free();
delete backAnimSurface;
if (pixel != 255) {
break; break;
} }
} }
@ -923,13 +929,11 @@ int PrinceEngine::checkMob(Graphics::Surface *screen, Common::Array<Mob> &mobLis
return -1; return -1;
} }
void PrinceEngine::printAt(uint32 slot, uint8 color, const char *s, uint16 x, uint16 y) { void PrinceEngine::printAt(uint32 slot, uint8 color, char *s, uint16 x, uint16 y) {
debugC(1, DebugChannel::kEngine, "PrinceEngine::printAt slot %d, color %d, x %02d, y %02d, str %s", slot, color, x, y, s); debugC(1, DebugChannel::kEngine, "PrinceEngine::printAt slot %d, color %d, x %02d, y %02d, str %s", slot, color, x, y, s);
char *destStr = (char *)malloc(strlen(s)); char *strPointer = s;
strcpy(destStr, s);
char *strPointer = destStr;
if (getLanguage() == Common::DE_DEU) { if (getLanguage() == Common::DE_DEU) {
while (*strPointer) { while (*strPointer) {
@ -961,7 +965,7 @@ void PrinceEngine::printAt(uint32 slot, uint8 color, const char *s, uint16 x, ui
} }
Text &text = _textSlots[slot]; Text &text = _textSlots[slot];
text._str = destStr; text._str = s;
text._x = x; text._x = x;
text._y = y; text._y = y;
text._color = color; text._color = color;
@ -1140,6 +1144,9 @@ void PrinceEngine::showSprite(Graphics::Surface *spriteSurface, int destX, int d
newDrawNode.freeSurfaceSMemory = freeSurfaceMemory; newDrawNode.freeSurfaceSMemory = freeSurfaceMemory;
newDrawNode.drawFunction = &_graph->drawTransparentDrawNode; newDrawNode.drawFunction = &_graph->drawTransparentDrawNode;
_drawNodeList.push_back(newDrawNode); _drawNodeList.push_back(newDrawNode);
} else if (freeSurfaceMemory) {
spriteSurface->free();
delete spriteSurface;
} }
} }
@ -1159,6 +1166,9 @@ void PrinceEngine::showSpriteShadow(Graphics::Surface *shadowSurface, int destX,
newDrawNode.freeSurfaceSMemory = freeSurfaceMemory; newDrawNode.freeSurfaceSMemory = freeSurfaceMemory;
newDrawNode.drawFunction = &_graph->drawAsShadowDrawNode; newDrawNode.drawFunction = &_graph->drawAsShadowDrawNode;
_drawNodeList.push_back(newDrawNode); _drawNodeList.push_back(newDrawNode);
} else if (freeSurfaceMemory) {
shadowSurface->free();
delete shadowSurface;
} }
} }
@ -1906,7 +1916,7 @@ void PrinceEngine::inventoryLeftMouseButton() {
int invObjExamEvent = _script->scanMobEvents(_invMobList[_selectedMob]._mask, _script->_scriptInfo.invObjExam); int invObjExamEvent = _script->scanMobEvents(_invMobList[_selectedMob]._mask, _script->_scriptInfo.invObjExam);
if (invObjExamEvent == -1) { if (invObjExamEvent == -1) {
// do_standard // do_standard
printAt(0, 216, _invMobList[_selectedMob]._examText.c_str(), kNormalWidth / 2, _invExamY); printAt(0, 216, (char *)_invMobList[_selectedMob]._examText.c_str(), kNormalWidth / 2, _invExamY);
_interpreter->setCurrentString(_invMobList[_selectedMob]._mask + 70000); _interpreter->setCurrentString(_invMobList[_selectedMob]._mask + 70000);
setVoice(0, 28, 1); setVoice(0, 28, 1);
playSample(28, 0); playSample(28, 0);

View file

@ -250,7 +250,7 @@ public:
virtual GUI::Debugger *getDebugger(); virtual GUI::Debugger *getDebugger();
void changeCursor(uint16 curId); void changeCursor(uint16 curId);
void printAt(uint32 slot, uint8 color, const char *s, uint16 x, uint16 y); void printAt(uint32 slot, uint8 color, char *s, uint16 x, uint16 y);
int calcText(const char *s); int calcText(const char *s);
static const uint8 MAXTEXTS = 32; static const uint8 MAXTEXTS = 32;

View file

@ -462,7 +462,7 @@ void Interpreter::debugInterpreter(const char *s, ...) {
Common::String str = Common::String::format("@0x%08X: ", _lastInstruction); Common::String str = Common::String::format("@0x%08X: ", _lastInstruction);
str += Common::String::format("op %04d: ", _lastOpcode); str += Common::String::format("op %04d: ", _lastOpcode);
//debugC(10, DebugChannel::kScript, "PrinceEngine::Script %s %s", str.c_str(), buf); //debugC(10, DebugChannel::kScript, "PrinceEngine::Script %s %s", str.c_str(), buf);
if (_mode == "fg") { if (!strcmp(_mode, "fg")) {
debug(10, "PrinceEngine::Script %s %s", str.c_str(), buf); debug(10, "PrinceEngine::Script %s %s", str.c_str(), buf);
} }
//debug("Prince::Script frame %08ld mode %s %s %s", _vm->_frameNr, _mode, str.c_str(), buf); //debug("Prince::Script frame %08ld mode %s %s %s", _vm->_frameNr, _mode, str.c_str(), buf);
@ -834,7 +834,7 @@ void Interpreter::O_SETSTRING() {
_currentString = offset; _currentString = offset;
if (offset >= 80000) { if (offset >= 80000) {
_string = (const byte *)_vm->_variaTxt->getString(offset - 80000); _string = (byte *)_vm->_variaTxt->getString(offset - 80000);
debugInterpreter("GetVaria %s", _string); debugInterpreter("GetVaria %s", _string);
} }
else if (offset < 2000) { else if (offset < 2000) {
@ -911,7 +911,7 @@ void Interpreter::O_XORFLAG() {
void Interpreter::O_GETMOBTEXT() { void Interpreter::O_GETMOBTEXT() {
uint16 mob = readScriptFlagValue(); uint16 mob = readScriptFlagValue();
_currentString = _vm->_locationNr * 100 + mob + 60001; _currentString = _vm->_locationNr * 100 + mob + 60001;
_string = (const byte *)_vm->_mobList[mob]._examText.c_str(); _string = (byte *)_vm->_mobList[mob]._examText.c_str();
debugInterpreter("O_GETMOBTEXT mob %d", mob); debugInterpreter("O_GETMOBTEXT mob %d", mob);
} }
@ -1239,7 +1239,7 @@ void Interpreter::O_PRINTAT() {
uint8 color = _flags->getFlagValue(Flags::KOLOR); uint8 color = _flags->getFlagValue(Flags::KOLOR);
_vm->printAt(slot, color, (const char *)_string, fr1, fr2); _vm->printAt(slot, color, (char *)_string, fr1, fr2);
increaseString(); increaseString();
} }

View file

@ -209,7 +209,7 @@ private:
//uint8 _savedStacktop; //uint8 _savedStacktop;
uint32 _waitFlag; uint32 _waitFlag;
const byte *_string; byte *_string;
uint32 _currentString; uint32 _currentString;
const char *_mode; const char *_mode;

View file

@ -42,12 +42,12 @@ bool VariaTxt::loadFromStream(Common::SeekableReadStream &stream) {
return true; return true;
} }
const char *VariaTxt::getString(uint32 stringId) { char *VariaTxt::getString(uint32 stringId) {
uint32 stringOffset = READ_LE_UINT32(_data + stringId * 4); uint32 stringOffset = READ_LE_UINT32(_data + stringId * 4);
if (stringOffset > _dataSize) { if (stringOffset > _dataSize) {
assert(false); assert(false);
} }
return (const char *)_data + stringOffset; return (char *)_data + stringOffset;
} }
} }

View file

@ -32,7 +32,7 @@ public:
bool loadFromStream(Common::SeekableReadStream &stream); bool loadFromStream(Common::SeekableReadStream &stream);
const char *getString(uint32 stringId); char *getString(uint32 stringId);
private: private:
uint32 _dataSize; uint32 _dataSize;