mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-16 14:50:17 +00:00
PRINCE: Memory leaks fix - showBackAnim(), printAt(), checkMob()"
This commit is contained in:
parent
7ebcbea0f9
commit
191b4cc8be
@ -46,6 +46,8 @@ GraphicsMan::GraphicsMan(PrinceEngine *vm)
|
||||
GraphicsMan::~GraphicsMan() {
|
||||
_frontScreen->free();
|
||||
delete _frontScreen;
|
||||
_screenForInventory->free();
|
||||
delete _screenForInventory;
|
||||
delete[] _shadowTable70;
|
||||
delete[] _shadowTable50;
|
||||
}
|
||||
|
@ -140,6 +140,8 @@ PrinceEngine::~PrinceEngine() {
|
||||
}
|
||||
_maskList.clear();
|
||||
|
||||
freeDrawNodes();
|
||||
|
||||
clearBackAnimList();
|
||||
|
||||
for (uint i = 0; i < _allInvList.size(); i++) {
|
||||
@ -404,6 +406,8 @@ bool PrinceEngine::loadLocation(uint16 locationNr) {
|
||||
_mobList[i]._visible = _script->getMobVisible(i);
|
||||
}
|
||||
|
||||
freeDrawNodes();
|
||||
|
||||
clearBackAnimList();
|
||||
_script->installBackAnims(_backAnimList, _room->_backAnim);
|
||||
|
||||
@ -855,8 +859,10 @@ int PrinceEngine::checkMob(Graphics::Surface *screen, Common::Array<Mob> &mobLis
|
||||
int phase = backAnim._showFrame;
|
||||
int phaseFrameIndex = backAnim._animData->getPhaseFrameIndex(phase);
|
||||
Graphics::Surface *backAnimSurface = backAnim._animData->getFrame(phaseFrameIndex);
|
||||
byte *pixel = (byte *)backAnimSurface->getBasePtr(mousePosCamera.x - backAnim._currX, mousePosCamera.y - backAnim._currY);
|
||||
if (*pixel != 255) {
|
||||
byte pixel = *(byte *)backAnimSurface->getBasePtr(mousePosCamera.x - backAnim._currX, mousePosCamera.y - backAnim._currY);
|
||||
backAnimSurface->free();
|
||||
delete backAnimSurface;
|
||||
if (pixel != 255) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -923,13 +929,11 @@ int PrinceEngine::checkMob(Graphics::Surface *screen, Common::Array<Mob> &mobLis
|
||||
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);
|
||||
|
||||
char *destStr = (char *)malloc(strlen(s));
|
||||
strcpy(destStr, s);
|
||||
char *strPointer = destStr;
|
||||
char *strPointer = s;
|
||||
|
||||
if (getLanguage() == Common::DE_DEU) {
|
||||
while (*strPointer) {
|
||||
@ -961,7 +965,7 @@ void PrinceEngine::printAt(uint32 slot, uint8 color, const char *s, uint16 x, ui
|
||||
}
|
||||
|
||||
Text &text = _textSlots[slot];
|
||||
text._str = destStr;
|
||||
text._str = s;
|
||||
text._x = x;
|
||||
text._y = y;
|
||||
text._color = color;
|
||||
@ -1140,6 +1144,9 @@ void PrinceEngine::showSprite(Graphics::Surface *spriteSurface, int destX, int d
|
||||
newDrawNode.freeSurfaceSMemory = freeSurfaceMemory;
|
||||
newDrawNode.drawFunction = &_graph->drawTransparentDrawNode;
|
||||
_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.drawFunction = &_graph->drawAsShadowDrawNode;
|
||||
_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);
|
||||
if (invObjExamEvent == -1) {
|
||||
// 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);
|
||||
setVoice(0, 28, 1);
|
||||
playSample(28, 0);
|
||||
|
@ -250,7 +250,7 @@ public:
|
||||
virtual GUI::Debugger *getDebugger();
|
||||
|
||||
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);
|
||||
|
||||
static const uint8 MAXTEXTS = 32;
|
||||
|
@ -462,7 +462,7 @@ void Interpreter::debugInterpreter(const char *s, ...) {
|
||||
Common::String str = Common::String::format("@0x%08X: ", _lastInstruction);
|
||||
str += Common::String::format("op %04d: ", _lastOpcode);
|
||||
//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("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;
|
||||
|
||||
if (offset >= 80000) {
|
||||
_string = (const byte *)_vm->_variaTxt->getString(offset - 80000);
|
||||
_string = (byte *)_vm->_variaTxt->getString(offset - 80000);
|
||||
debugInterpreter("GetVaria %s", _string);
|
||||
}
|
||||
else if (offset < 2000) {
|
||||
@ -911,7 +911,7 @@ void Interpreter::O_XORFLAG() {
|
||||
void Interpreter::O_GETMOBTEXT() {
|
||||
uint16 mob = readScriptFlagValue();
|
||||
_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);
|
||||
}
|
||||
@ -1239,7 +1239,7 @@ void Interpreter::O_PRINTAT() {
|
||||
|
||||
uint8 color = _flags->getFlagValue(Flags::KOLOR);
|
||||
|
||||
_vm->printAt(slot, color, (const char *)_string, fr1, fr2);
|
||||
_vm->printAt(slot, color, (char *)_string, fr1, fr2);
|
||||
|
||||
increaseString();
|
||||
}
|
||||
|
@ -209,7 +209,7 @@ private:
|
||||
//uint8 _savedStacktop;
|
||||
uint32 _waitFlag;
|
||||
|
||||
const byte *_string;
|
||||
byte *_string;
|
||||
uint32 _currentString;
|
||||
const char *_mode;
|
||||
|
||||
|
@ -42,12 +42,12 @@ bool VariaTxt::loadFromStream(Common::SeekableReadStream &stream) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *VariaTxt::getString(uint32 stringId) {
|
||||
char *VariaTxt::getString(uint32 stringId) {
|
||||
uint32 stringOffset = READ_LE_UINT32(_data + stringId * 4);
|
||||
if (stringOffset > _dataSize) {
|
||||
assert(false);
|
||||
}
|
||||
return (const char *)_data + stringOffset;
|
||||
return (char *)_data + stringOffset;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
|
||||
bool loadFromStream(Common::SeekableReadStream &stream);
|
||||
|
||||
const char *getString(uint32 stringId);
|
||||
char *getString(uint32 stringId);
|
||||
|
||||
private:
|
||||
uint32 _dataSize;
|
||||
|
Loading…
Reference in New Issue
Block a user