Skip to content

Commit

Permalink
GRAPHICS: MACGUI: Crash-proof window management.
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Oct 14, 2019
1 parent dfc0a51 commit 5acaaed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
27 changes: 16 additions & 11 deletions graphics/macgui/macwindowmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ MacWindowManager::MacWindowManager() {
}

MacWindowManager::~MacWindowManager() {
for (int i = 0; i < _lastId; i++)
delete _windows[i];
for (Common::HashMap<uint, BaseMacWindow *>::iterator it = _windows.begin(); it != _windows.end(); it++)
delete it->_value;

delete _fontMan;
delete _screenCopy;
Expand Down Expand Up @@ -223,14 +223,14 @@ MacTextWindow *MacWindowManager::addTextWindow(const MacFont *font, int fgcolor,


void MacWindowManager::addWindowInitialized(MacWindow *macwindow) {
_windows.push_back(macwindow);
_windows[macwindow->getId()] = macwindow;
_windowStack.push_back(macwindow);
}

MacMenu *MacWindowManager::addMenu() {
_menu = new MacMenu(getNextId(), _screen->getBounds(), this);

_windows.push_back(_menu);
_windows[_menu->getId()] = _menu;

return _menu;
}
Expand Down Expand Up @@ -431,7 +431,13 @@ void MacWindowManager::removeMarked() {
}
_windowsToRemove.clear();
_needsRemoval = false;
_lastId = _windows.size();

// Do we need compact lastid?
_lastId = 0;
for (Common::HashMap<uint, BaseMacWindow *>::iterator lit = _windows.begin(); lit != _windows.end(); lit++) {
if (lit->_key > (uint)_lastId)
_lastId = lit->_key;
}
}

void MacWindowManager::removeFromStack(BaseMacWindow *target) {
Expand All @@ -445,14 +451,13 @@ void MacWindowManager::removeFromStack(BaseMacWindow *target) {
}

void MacWindowManager::removeFromWindowList(BaseMacWindow *target) {
int size = _windows.size();
int ndx = 0;
for (int i = 0; i < size; i++) {
if (_windows[i] == target) {
ndx = i;
// _windows.erase(target->getId()); // Is applicable?
for (Common::HashMap<uint, BaseMacWindow *>::iterator it = _windows.begin(); it != _windows.end(); it++) {
if (it->_value == target) {
_windows.erase(it);
break;
}
}
_windows.remove_at(ndx);
}

/////////////////
Expand Down
4 changes: 2 additions & 2 deletions graphics/macgui/macwindowmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#ifndef GRAPHICS_MACGUI_MACWINDOWMANAGER_H
#define GRAPHICS_MACGUI_MACWINDOWMANAGER_H

#include "common/array.h"
#include "common/hashmap.h"
#include "common/list.h"
#include "common/events.h"

Expand Down Expand Up @@ -243,7 +243,7 @@ class MacWindowManager {

private:
Common::List<BaseMacWindow *> _windowStack;
Common::Array<BaseMacWindow *> _windows;
Common::HashMap<uint, BaseMacWindow *> _windows;

Common::List<BaseMacWindow *> _windowsToRemove;
bool _needsRemoval;
Expand Down

0 comments on commit 5acaaed

Please sign in to comment.