[Scummvm-git-logs] scummvm master -> 58fd0f574704cd8ab729dba0c0f281c72c498646

sluicebox noreply at scummvm.org
Sat Oct 25 07:34:28 UTC 2025


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .

Summary:
58fd0f5747 SLUDGE: Fix severe memory leak when drawing sprites


Commit: 58fd0f574704cd8ab729dba0c0f281c72c498646
    https://github.com/scummvm/scummvm/commit/58fd0f574704cd8ab729dba0c0f281c72c498646
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2025-10-25T00:33:32-07:00

Commit Message:
SLUDGE: Fix severe memory leak when drawing sprites

Should fix bug #16315 where memory was exhausted on RISC OS

Changed paths:
    engines/sludge/sprites.cpp


diff --git a/engines/sludge/sprites.cpp b/engines/sludge/sprites.cpp
index 0d72ff90e48..307a55af3d9 100644
--- a/engines/sludge/sprites.cpp
+++ b/engines/sludge/sprites.cpp
@@ -483,21 +483,14 @@ bool GraphicsManager::scaleSprite(Sprite &single, const SpritePalette &fontPal,
 	}
 
 	Graphics::Surface *blitted = &single.surface;
-	Graphics::Surface *ptr = applyLightmapToSprite(blitted, thisPerson, mirror, x, y, x1, y1, diffX, diffY);
+	Graphics::Surface *toDelete = applyLightmapToSprite(blitted, thisPerson, mirror, x, y, x1, y1, diffX, diffY);
 
 	// Use Managed surface to scale and blit
 	if (!_zBuffer->numPanels) {
 		Graphics::ManagedSurface tmp;
 		tmp.copyFrom(*blitted);
 		tmp.blendBlitTo(_renderSurface, x1, y1, (mirror ? Graphics::FLIP_H : Graphics::FLIP_NONE), nullptr, MS_ARGB(255 - thisPerson->transparency, 255, 255, 255), diffX, diffY);
-
-		if (ptr) {
-			ptr->free();
-			delete ptr;
-			ptr = nullptr;
-		}
 	} else {
-
 		// TODO: you dont need to copy the whole render surface, just the part to which the sprite may be drawn
 		Graphics::ManagedSurface scaled;
 		scaled.copyFrom(_renderSurface);
@@ -509,6 +502,12 @@ bool GraphicsManager::scaleSprite(Sprite &single, const SpritePalette &fontPal,
 		drawSpriteToZBuffer(0, 0, z, scaled.rawSurface());
 	}
 
+	if (toDelete) {
+		toDelete->free();
+		delete toDelete;
+		toDelete = nullptr;
+	}
+
 	// Are we pointing at the sprite?
 	if (_vm->_evtMan->mouseX() >= x1 && _vm->_evtMan->mouseX() < x2
 			&& _vm->_evtMan->mouseY() >= y1 && _vm->_evtMan->mouseY() < y2) {
@@ -561,7 +560,7 @@ void GraphicsManager::fixScaleSprite(int x, int y, Sprite &single, const SpriteP
 	}
 
 	Graphics::Surface *blitted = &single.surface;
-	Graphics::Surface *ptr = applyLightmapToSprite(blitted, thisPerson, mirror, x, y, x1, y1, diffX, diffY);
+	Graphics::Surface *toDelete = applyLightmapToSprite(blitted, thisPerson, mirror, x, y, x1, y1, diffX, diffY);
 
 	// draw backdrop
 	drawBackDrop();
@@ -576,12 +575,6 @@ void GraphicsManager::fixScaleSprite(int x, int y, Sprite &single, const SpriteP
 		Graphics::ManagedSurface tmp;
 		tmp.copyFrom(single.surface);
 		tmp.blendBlitTo(_renderSurface, x1, y1, (mirror ? Graphics::FLIP_H : Graphics::FLIP_NONE), nullptr, MS_ARGB((uint)255, (uint)255, (uint)255, (uint)255), diffX, diffY);
-
-		if (ptr) {
-			ptr->free();
-			delete ptr;
-			ptr = nullptr;
-		}
 	} else {
 		Graphics::ManagedSurface scaled;
 		scaled.copyFrom(_renderSurface);
@@ -591,7 +584,12 @@ void GraphicsManager::fixScaleSprite(int x, int y, Sprite &single, const SpriteP
 		tmp.blendBlitTo(scaled, x1, y1, (mirror ? Graphics::FLIP_H : Graphics::FLIP_NONE), nullptr, MS_ARGB(255 - thisPerson->transparency, 255, 255, 255), diffX, diffY);
 
 		drawSpriteToZBuffer(0, 0, z, scaled.rawSurface());
+	}
 
+	if (toDelete) {
+		toDelete->free();
+		delete toDelete;
+		toDelete = nullptr;
 	}
 
 	// copy screen to backdrop




More information about the Scummvm-git-logs mailing list