From 0d172c8ca695ae67b881b92add19e488c6053fbb Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 18 May 2019 17:13:55 -1000 Subject: GLK: Fix freeing closed windows --- engines/glk/windows.cpp | 22 +++++++++++++++++++--- engines/glk/windows.h | 5 +++++ 2 files changed, 24 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/glk/windows.cpp b/engines/glk/windows.cpp index ffb1fbf906..7b6833ff59 100644 --- a/engines/glk/windows.cpp +++ b/engines/glk/windows.cpp @@ -187,10 +187,21 @@ void Windows::windowClose(Window *win, StreamResult *result) { return; } + // Detach window being closed from parent pair window + pairWin->_children.remove_at(index); + win->_parent = nullptr; + if (!(pairWin->_dir & winmethod_Arbitrary)) { - sibWin = (index = ((int)pairWin->_children.size() - 1)) ? - pairWin->_children.front() : pairWin->_children[index + 1]; + // Get the remaining child window + assert(pairWin->_children.size() == 1); + sibWin = pairWin->_children.front(); + + // Detach it from the pair window + index = pairWin->_children.indexOf(sibWin); + assert(index >= 0); + pairWin->_children.remove_at(index); + // Set up window as either the singular root, or grandparent pair window if one exists grandparWin = dynamic_cast(pairWin->_parent); if (!grandparWin) { _rootWin = sibWin; @@ -453,7 +464,12 @@ uint Windows::rgbShift(uint color) { /*--------------------------------------------------------------------------*/ Windows::iterator &Windows::iterator::operator++() { - _current = _windows->iterateTreeOrder(_current); + _current = _current->_next; + return *this; +} + +Windows::iterator &Windows::iterator::operator--() { + _current = _current->_prev; return *this; } diff --git a/engines/glk/windows.h b/engines/glk/windows.h index 9cab07acf9..1974b3e4a4 100644 --- a/engines/glk/windows.h +++ b/engines/glk/windows.h @@ -73,6 +73,11 @@ public: */ iterator &operator++(); + /** + * Move to previous + */ + iterator &operator--(); + /** * Equality test */ -- cgit v1.2.3