summaryrefslogtreecommitdiff
path: root/window.c
diff options
context:
space:
mode:
authorDarkvater <Darkvater@openttd.org>2006-12-30 01:08:12 +0000
committerDarkvater <Darkvater@openttd.org>2006-12-30 01:08:12 +0000
commit41c6c79a25e97af665d71d586c334a9036445a51 (patch)
tree13f826d8c6dce81a4613bf08ea1ebd6b2231fa0e /window.c
parenteb3b73465cc1969a8539dc9ed72c1c05399d3ca2 (diff)
downloadopenttd-41c6c79a25e97af665d71d586c334a9036445a51.tar.xz
(svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
parent window is deleted it deletes its child (always) and in turn, through some code the child initiates the deletion of the parent which, if not guarded against, deletes the child and so on...
Diffstat (limited to 'window.c')
-rw-r--r--window.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/window.c b/window.c
index 75da457b5..1a12c7c6b 100644
--- a/window.c
+++ b/window.c
@@ -308,10 +308,13 @@ Window **FindWindowZPosition(const Window *w)
{
Window **wz;
- for (wz = _z_windows;; wz++) {
- assert(wz < _last_z_window);
+ for (wz = _z_windows; wz != _last_z_window; wz++) {
if (*wz == w) return wz;
}
+
+ DEBUG(misc, 3, "Window (class %d, number %d) is not open, probably removed by recursive calls",
+ w->window_class, w->window_number);
+ return NULL;
}
void DeleteWindow(Window *w)
@@ -342,6 +345,7 @@ void DeleteWindow(Window *w)
/* Find the window in the z-array, and effectively remove it
* by moving all windows after it one to the left */
wz = FindWindowZPosition(w);
+ if (wz == NULL) return;
memmove(wz, wz + 1, (byte*)_last_z_window - (byte*)wz);
_last_z_window--;
}