diff options
author | Eugene Sandulenko | 2017-07-30 09:18:42 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2017-08-01 10:42:21 +0200 |
commit | 645ee64da0f837245443842d53621e8fd5ac924f (patch) | |
tree | a9d0e6fe46e23b73ca015a47fdf2a64a11d92c24 /graphics | |
parent | 73b6b12cbb926c2e21020afa4a984bbeaeac3db6 (diff) | |
download | scummvm-rg350-645ee64da0f837245443842d53621e8fd5ac924f.tar.gz scummvm-rg350-645ee64da0f837245443842d53621e8fd5ac924f.tar.bz2 scummvm-rg350-645ee64da0f837245443842d53621e8fd5ac924f.zip |
GRAPHICS: MACGUI: Avoid double free of MacTextWindow
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/macgui/mactextwindow.cpp | 4 | ||||
-rw-r--r-- | graphics/macgui/macwindowmanager.cpp | 10 | ||||
-rw-r--r-- | graphics/macgui/macwindowmanager.h | 7 |
3 files changed, 9 insertions, 12 deletions
diff --git a/graphics/macgui/mactextwindow.cpp b/graphics/macgui/mactextwindow.cpp index 333bdcd3d2..e3e2f16acb 100644 --- a/graphics/macgui/mactextwindow.cpp +++ b/graphics/macgui/mactextwindow.cpp @@ -28,9 +28,7 @@ namespace Graphics { MacTextWindow::MacTextWindow(MacWindowManager *wm, const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment) : - MacWindow(wm->getNextId(), true, true, true, wm) { - - wm->addWindowInitialized(this); + MacWindow(wm->getLastId(), true, true, true, wm) { _font = font; _mactext = new MacText("", _wm, font, fgcolor, bgcolor, maxWidth, textAlignment); diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp index 1e4c49fa76..d3f7d22c4d 100644 --- a/graphics/macgui/macwindowmanager.cpp +++ b/graphics/macgui/macwindowmanager.cpp @@ -176,8 +176,7 @@ MacWindowManager::~MacWindowManager() { MacWindow *MacWindowManager::addWindow(bool scrollable, bool resizable, bool editable) { MacWindow *w = new MacWindow(_lastId, scrollable, resizable, editable, this); - _windows.push_back(w); - _windowStack.push_back(w); + addWindowInitialized(w); setActive(getNextId()); @@ -187,8 +186,7 @@ MacWindow *MacWindowManager::addWindow(bool scrollable, bool resizable, bool edi MacTextWindow *MacWindowManager::addTextWindow(const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment) { MacTextWindow *w = new MacTextWindow(this, font, fgcolor, bgcolor, maxWidth, textAlignment); - _windows.push_back(w); - _windowStack.push_back(w); + addWindowInitialized(w); setActive(getNextId()); @@ -201,10 +199,6 @@ void MacWindowManager::addWindowInitialized(MacWindow *macwindow) { _windowStack.push_back(macwindow); } -int MacWindowManager::getNextId() { - return _lastId++; -} - MacMenu *MacWindowManager::addMenu() { _menu = new MacMenu(getNextId(), _screen->getBounds(), this); diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h index 61f4899481..963fc358dd 100644 --- a/graphics/macgui/macwindowmanager.h +++ b/graphics/macgui/macwindowmanager.h @@ -116,10 +116,15 @@ public: */ void addWindowInitialized(MacWindow *macwindow); /** + * Returns the last allocated id + * @return last allocated window id + */ + int getLastId() { return _lastId; } + /** * Returns the next available id and the increments the internal counter. * @return next (new) window id that can be used */ - int getNextId(); + int getNextId() { return _lastId++; } /** * Add the menu to the desktop. * Note that the returned menu is empty, and therefore must be filled |