diff options
author | Johannes Schickel | 2010-04-11 17:26:32 +0000 |
---|---|---|
committer | Johannes Schickel | 2010-04-11 17:26:32 +0000 |
commit | 29172d48447d1418783333b93677f9151fc424c4 (patch) | |
tree | e5c6025b5446c4e016427a65e51cf9e7fbfd4632 /engines/scumm/scumm.cpp | |
parent | 2e6b40798d3f945e1d1e36696c2af73506e8586b (diff) | |
download | scummvm-rg350-29172d48447d1418783333b93677f9151fc424c4.tar.gz scummvm-rg350-29172d48447d1418783333b93677f9151fc424c4.tar.bz2 scummvm-rg350-29172d48447d1418783333b93677f9151fc424c4.zip |
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.
svn-id: r48620
Diffstat (limited to 'engines/scumm/scumm.cpp')
-rw-r--r-- | engines/scumm/scumm.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp index 5555d961b2..a24fc650a5 100644 --- a/engines/scumm/scumm.cpp +++ b/engines/scumm/scumm.cpp @@ -550,6 +550,12 @@ ScummEngine::ScummEngine(OSystem *syst, const DetectorResult &dr) 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 @@ ScummEngine::~ScummEngine() { delete _res; delete _gdi; + + // Remove our cursors again to prevent memory leaks + CursorMan.popCursor(); + CursorMan.popCursorPalette(); } |