[Scummvm-git-logs] scummvm master -> 187e4124f8a44090009199d0607ef5642bc4aadf
kelmer44
noreply at scummvm.org
Thu Sep 18 20:16:24 UTC 2025
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .
Summary:
04de5df90a TOT: Fixes leaks in conversations and inventory
187e4124f8 GRAPHICS: FONTS: Fixes leak on BgiFont
Commit: 04de5df90afc925309308918a2710e259fcf966d
https://github.com/scummvm/scummvm/commit/04de5df90afc925309308918a2710e259fcf966d
Author: kelmer (kelmer at gmail.com)
Date: 2025-09-18T22:16:01+02:00
Commit Message:
TOT: Fixes leaks in conversations and inventory
Changed paths:
engines/tot/engine.cpp
engines/tot/resources.cpp
engines/tot/types.h
engines/tot/util.cpp
engines/tot/util.h
diff --git a/engines/tot/engine.cpp b/engines/tot/engine.cpp
index 3e48610896d..06250edf61f 100644
--- a/engines/tot/engine.cpp
+++ b/engines/tot/engine.cpp
@@ -591,16 +591,21 @@ void TotEngine::animatedSequence(uint numSequence) {
_graphics->advancePaletteAnim();
_graphics->putShape(animX, animY, animptr);
}
- _screenLayers[_curObject.depth - 1] = nullptr;
+
+ clearScreenLayer(_curObject.depth - 1);
_graphics->restoreBackground();
animIndex = _mainCharAnimation.depth;
_mainCharAnimation.depth = 30;
+ if (g_engine->_screenLayers[13]) {
+ free(g_engine->_screenLayers[13]);
+ }
_screenLayers[13] = animptr;
_depthMap[13].posx = animX;
_depthMap[13].posy = animY;
assembleScreen();
_graphics->drawScreen(_sceneBackground);
- _screenLayers[13] = nullptr;
+
+ clearScreenLayer(13);
_mainCharAnimation.depth = animIndex;
drawInventory();
for (animIndex = 32; animIndex <= secFrameCount; animIndex++) {
@@ -637,12 +642,15 @@ void TotEngine::animatedSequence(uint numSequence) {
}
}
animIndex = _mainCharAnimation.depth;
- _mainCharAnimation.depth = 30;
+ _mainCharAnimation.depth = 30;
+ if (g_engine->_screenLayers[12]) {
+ free(g_engine->_screenLayers[12]);
+ }
_screenLayers[12] = animptr;
_depthMap[12].posx = animX;
_depthMap[12].posy = animY;
disableSecondAnimation();
- _screenLayers[12] = nullptr;
+ clearScreenLayer(12);
_mainCharAnimation.depth = animIndex;
_graphics->drawScreen(_sceneBackground);
for (animIndex = 9; animIndex <= secFrameCount; animIndex++) {
@@ -672,6 +680,9 @@ void TotEngine::animatedSequence(uint numSequence) {
animFrameSize = animationFile.readUint16LE();
secFrameCount = animationFile.readByte();
animationFile.readByte();
+ if (g_engine->_screenLayers[6]) {
+ free(g_engine->_screenLayers[6]);
+ }
_screenLayers[6] = (byte *)malloc(animFrameSize);
_depthMap[6].posx = _secondaryAnimation.posx + 5;
_depthMap[6].posy = _secondaryAnimation.posy - 6;
@@ -693,7 +704,7 @@ void TotEngine::animatedSequence(uint numSequence) {
} while (animIndex != secFrameCount && !shouldQuit());
animationFile.close();
_sound->stopVoc();
- _screenLayers[6] = nullptr;
+ clearScreenLayer(6);
_currentRoomData->animationFlag = true;
} break;
}
@@ -1360,6 +1371,9 @@ void TotEngine::nicheAnimation(byte nicheDir, int32 bitmap) {
// Room with Red
if (_currentRoomData->code == 24) {
+ if (g_engine->_screenLayers[1]) {
+ free(g_engine->_screenLayers[1]);
+ }
_screenLayers[1] = (byte *)malloc(3660);
readBitmap(1382874, _screenLayers[1], 3652, 319);
uint16 object1Width = READ_LE_UINT16(_screenLayers[1]);
@@ -1412,8 +1426,7 @@ void TotEngine::nicheAnimation(byte nicheDir, int32 bitmap) {
_graphics->drawScreen(_sceneBackground);
if (_currentRoomData->code == 24) {
- free(_screenLayers[1]);
- _screenLayers[1] = nullptr;
+ clearScreenLayer(1);
}
}
@@ -1466,7 +1479,7 @@ void TotEngine::pickupScreenObject() {
} break;
default: {
animatePickup1(_charFacingDirection, 0);
- _screenLayers[_curObject.depth - 1] = nullptr;
+ clearScreenLayer(_curObject.depth - 1);
_graphics->restoreBackground();
assembleScreen();
_graphics->drawScreen(_sceneBackground);
@@ -1525,7 +1538,8 @@ void TotEngine::pickupScreenObject() {
with.depth = 1;
loadScreenLayer(with.coordx, with.coordy, with.bitmapSize, with.bitmapPointer, with.depth);
}
- _screenLayers[_curObject.depth - 1] = nullptr;
+
+ clearScreenLayer(_curObject.depth -1);
_graphics->restoreBackground();
assembleScreen();
@@ -1685,7 +1699,7 @@ void TotEngine::pickupScreenObject() {
with.coordy = 0;
with.depth = 0;
}
- _screenLayers[3] = nullptr;
+ clearScreenLayer(3);
disableSecondAnimation();
_graphics->drawScreen(_sceneBackground);
animatePickup2(2, 1);
@@ -1694,7 +1708,7 @@ void TotEngine::pickupScreenObject() {
} break;
default: {
animatePickup1(_charFacingDirection, 1);
- _screenLayers[_curObject.depth - 1] = nullptr;
+ clearScreenLayer(_curObject.depth - 1);
_graphics->restoreBackground();
assembleScreen();
_graphics->drawScreen(_sceneBackground);
@@ -1726,7 +1740,7 @@ void TotEngine::pickupScreenObject() {
} break;
case 659: { // spider web, puts bird and ring on the floor
animatePickup1(3, 2);
- _screenLayers[_curObject.depth - 1] = nullptr;
+ clearScreenLayer(_curObject.depth - 1);
{ // bird
RoomBitmapRegister &with = _currentRoomData->screenLayers[2];
@@ -1754,7 +1768,7 @@ void TotEngine::pickupScreenObject() {
} break;
default: {
animatePickup1(_charFacingDirection, 2);
- _screenLayers[_curObject.depth - 1] = nullptr;
+ clearScreenLayer(_curObject.depth - 1);
assembleScreen();
_graphics->drawScreen(_sceneBackground);
animatePickup2(_charFacingDirection, 2);
@@ -2865,7 +2879,7 @@ void TotEngine::useScreenObject() {
_currentRoomData->screenLayers[4].coordx = 0;
_currentRoomData->screenLayers[4].coordy = 0;
_currentRoomData->screenLayers[4].depth = 0;
- _screenLayers[7] = nullptr;
+ clearScreenLayer(7);
_graphics->restoreBackground();
assembleScreen();
_graphics->drawScreen(_sceneBackground);
@@ -2923,7 +2937,7 @@ void TotEngine::useScreenObject() {
_currentRoomData->screenLayers[4].coordx = 0;
_currentRoomData->screenLayers[4].coordy = 0;
_currentRoomData->screenLayers[4].depth = 0;
- _screenLayers[7] = nullptr;
+ clearScreenLayer(7);
_graphics->restoreBackground();
assembleScreen();
_graphics->drawScreen(_sceneBackground);
@@ -3034,7 +3048,7 @@ void TotEngine::useScreenObject() {
_currentRoomData->screenLayers[0].coordx = 0;
_currentRoomData->screenLayers[0].coordy = 0;
_currentRoomData->screenLayers[0].depth = 0;
- _screenLayers[2] = nullptr;
+ clearScreenLayer(2);
for (invIndex = 6; invIndex <= 9; invIndex++)
_currentRoomData->mouseGrid[26][invIndex] = 3;
for (invIndex = 3; invIndex <= 5; invIndex++)
@@ -3283,7 +3297,7 @@ void TotEngine::openScreenObject() {
else {
_mouse->hide();
animatePickup1(0, 1);
- _screenLayers[_curObject.depth - 1] = nullptr;
+ clearScreenLayer(_curObject.depth - 1);
yIndex = 0;
while (_currentRoomData->screenLayers[yIndex].depth != _curObject.depth && yIndex != 15) {
yIndex++;
@@ -3319,7 +3333,7 @@ void TotEngine::openScreenObject() {
else {
_mouse->hide();
animatePickup1(1, 1);
- _screenLayers[_curObject.depth - 1] = nullptr;
+ clearScreenLayer(_curObject.depth - 1);
yIndex = 0;
while (_currentRoomData->screenLayers[yIndex].depth != _curObject.depth && yIndex != 14) {
yIndex++;
@@ -4303,9 +4317,7 @@ void TotEngine::loadScreen() {
void TotEngine::clearScreenLayers() {
for (int i = 0; i < kNumScreenOverlays; i++) {
- if (_screenLayers[i] != nullptr)
- free(_screenLayers[i]);
- _screenLayers[i] = nullptr;
+ clearScreenLayer(i);
}
}
@@ -4334,6 +4346,9 @@ void TotEngine::freeInventory() {
}
void TotEngine::loadScreenLayerWithDepth(uint coordx, uint coordy, uint bitmapSize, int32 bitmapIndex, uint depth) {
+ if (g_engine->_screenLayers[depth]) {
+ free(g_engine->_screenLayers[depth]);
+ }
_screenLayers[depth] = (byte *)malloc(bitmapSize);
readBitmap(bitmapIndex, _screenLayers[depth], bitmapSize, 319);
diff --git a/engines/tot/resources.cpp b/engines/tot/resources.cpp
index bd9c40b2bf2..b272b80f185 100644
--- a/engines/tot/resources.cpp
+++ b/engines/tot/resources.cpp
@@ -43,13 +43,17 @@ void TotEngine::loadCharAnimation() {
_mainCharFrameSize = characterFile.readUint16LE();
- for (int i = 0; i <= 3; i++)
+ for (int i = 0; i < 4; i++)
for (int j = 0; j < kWalkFrameCount; j++) {
+ if (g_engine->_mainCharAnimation.bitmap[i][j])
+ free(g_engine->_mainCharAnimation.bitmap[i][j]);
_mainCharAnimation.bitmap[i][j] = (byte *)malloc(_mainCharFrameSize);
characterFile.read(_mainCharAnimation.bitmap[i][j], _mainCharFrameSize);
}
for (int i = 0; i < 4; i++)
for (int j = kWalkFrameCount; j < (kWalkFrameCount + 10 * 3); j++) {
+ if (g_engine->_mainCharAnimation.bitmap[i][j])
+ free(g_engine->_mainCharAnimation.bitmap[i][j]);
_mainCharAnimation.bitmap[i][j] = (byte *)malloc(_mainCharFrameSize);
characterFile.read(_mainCharAnimation.bitmap[i][j], _mainCharFrameSize);
}
@@ -91,7 +95,7 @@ void TotEngine::readConversationFile() {
byte *buf = (byte *)malloc(fileSize);
conversationFile.read(buf, fileSize);
- _conversationData = new Common::MemorySeekableReadWriteStream(buf, fileSize, DisposeAfterUse::NO);
+ _conversationData = new Common::MemorySeekableReadWriteStream(buf, fileSize, DisposeAfterUse::YES);
conversationFile.close();
}
diff --git a/engines/tot/types.h b/engines/tot/types.h
index 9dec3752c03..77af95dd618 100644
--- a/engines/tot/types.h
+++ b/engines/tot/types.h
@@ -107,9 +107,9 @@ struct SecondaryAnim {
};
struct InventoryEntry {
- uint16 bitmapIndex;
- uint16 code;
- Common::String objectName;
+ uint16 bitmapIndex = -1;
+ uint16 code = -1;
+ Common::String objectName = "";
};
/**
diff --git a/engines/tot/util.cpp b/engines/tot/util.cpp
index 0b7b249ccf1..67dd6f72667 100644
--- a/engines/tot/util.cpp
+++ b/engines/tot/util.cpp
@@ -533,4 +533,12 @@ void newSecondaryAnimationFrame() {
}
g_engine->_curSecondaryAnimationFrame = (byte *)malloc(g_engine->_secondaryAnimFrameSize);
}
+
+void clearScreenLayer(uint pos) {
+ if (g_engine->_screenLayers[pos]) {
+ free(g_engine->_screenLayers[pos]);
+ }
+ g_engine->_screenLayers[pos] = nullptr;
+}
+
} // End of namespace Tot
diff --git a/engines/tot/util.h b/engines/tot/util.h
index 3b06a3c137e..880430df71c 100644
--- a/engines/tot/util.h
+++ b/engines/tot/util.h
@@ -82,6 +82,8 @@ const int32 *getOffsetsByCurrentLanguage();
void newSecondaryAnimationFrame();
+void clearScreenLayer(uint pos);
+
inline bool isLanguageSpanish() {
return g_engine->_lang == Common::ES_ESP;
};
Commit: 187e4124f8a44090009199d0607ef5642bc4aadf
https://github.com/scummvm/scummvm/commit/187e4124f8a44090009199d0607ef5642bc4aadf
Author: kelmer (kelmer at gmail.com)
Date: 2025-09-18T22:16:01+02:00
Commit Message:
GRAPHICS: FONTS: Fixes leak on BgiFont
Changed paths:
graphics/fonts/bgifont.h
diff --git a/graphics/fonts/bgifont.h b/graphics/fonts/bgifont.h
index 12ab1b7bfb2..2628165392e 100644
--- a/graphics/fonts/bgifont.h
+++ b/graphics/fonts/bgifont.h
@@ -71,6 +71,9 @@ private:
int widths[256];
int offsets[256];
Graphics::Surface *surface;
+ ~CachedFont() {
+ delete surface;
+ }
};
uint16 _charCount;
More information about the Scummvm-git-logs
mailing list