[Scummvm-cvs-logs] SF.net SVN: scummvm:[48620] scummvm/trunk/engines/scumm/scumm.cpp

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Sun Apr 11 19:26:33 CEST 2010


Revision: 48620
          http://scummvm.svn.sourceforge.net/scummvm/?rev=48620&view=rev
Author:   lordhoto
Date:     2010-04-11 17:26:32 +0000 (Sun, 11 Apr 2010)

Log Message:
-----------
Fix a memory leak in SCUMM which was caused by the SCUMM engine never removing its cursor from CursorMan.

The problem here was that SCUMM only uses CursorMan.replaceCursor. When no
cursor had been setup before it would cause the SCUMM cursor to be never
removed from CursorMan, since in this case replaceCursor just uses pushCursor.
To avoid this problem I am just pushing a dummy cursor (and palette, since
that is used in SCUMM HE games too) on engine setup and removing it on engine
destruction.

Actually every engine should setup their first cursor via CursorMan.pushCursor
and then on quit remove it again via CursorMan.popCursor. Using
CursorMan.replaceCursor is *no* good idea for the first cursor to setup, since
that might either replace an existing cursor, thus destroying the caller's
cursor, or pushing a new cursor on the stack, which might result in a leak.
This would also result in making a call to CursorMan.popCursor unsafe, since
that might also impact the caller's cursor setup again.

Modified Paths:
--------------
    scummvm/trunk/engines/scumm/scumm.cpp

Modified: scummvm/trunk/engines/scumm/scumm.cpp
===================================================================
--- scummvm/trunk/engines/scumm/scumm.cpp	2010-04-11 16:27:11 UTC (rev 48619)
+++ scummvm/trunk/engines/scumm/scumm.cpp	2010-04-11 17:26:32 UTC (rev 48620)
@@ -550,6 +550,12 @@
 		Common::addDebugChannel(debugChannels[i].flag,  debugChannels[i].channel, debugChannels[i].desc);
 
 	g_eventRec.registerRandomSource(_rnd, "scumm");
+
+	// Setup a dummy cursor and palette. The latter is only
+	// required by HE, thus we might consider to do that only
+	// for HE games.
+	CursorMan.pushCursor(NULL, 0, 0, 0, 0, 0);
+	CursorMan.pushCursorPalette(NULL, 0, 0);
 }
 
 
@@ -606,6 +612,10 @@
 
 	delete _res;
 	delete _gdi;
+
+	// Remove our cursors again to prevent memory leaks
+	CursorMan.popCursor();
+	CursorMan.popCursorPalette();
 }
 
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list