summaryrefslogtreecommitdiff
path: root/viewport.c
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2006-11-18 16:47:02 +0000
committerDarkvater <darkvater@openttd.org>2006-11-18 16:47:02 +0000
commitb3c48c0a84323838b5104e422d11b8a1250325c8 (patch)
tree8112ec497b55f459780ad628193295c31cabfe28 /viewport.c
parentaa97b61a27cecfb6e06526fa74d95629cc7259a5 (diff)
downloadopenttd-b3c48c0a84323838b5104e422d11b8a1250325c8.tar.xz
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
structs inside their array, and possibly invalidating pointers higher up. Meaning that any function called within an wndproc could cause unknown/invalid pointers once control was returned to this function. Solved by the introduction of an extra abstraction layer, an array of z-window positions that is only concerned with the pointers.
Diffstat (limited to 'viewport.c')
-rw-r--r--viewport.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/viewport.c b/viewport.c
index d413dec2a..e9ce5cdc7 100644
--- a/viewport.c
+++ b/viewport.c
@@ -183,35 +183,38 @@ void AssignWindowViewport(Window *w, int x, int y,
static Point _vp_move_offs;
-static void DoSetViewportPosition(const Window *w, int left, int top, int width, int height)
+static void DoSetViewportPosition(const Window* const *wz, int left, int top, int width, int height)
{
- for (; w < _last_window; w++) {
+
+ for (; wz != _last_z_window; wz++) {
+ const Window *w = *wz;
+
if (left + width > w->left &&
w->left + w->width > left &&
top + height > w->top &&
w->top + w->height > top) {
if (left < w->left) {
- DoSetViewportPosition(w, left, top, w->left - left, height);
- DoSetViewportPosition(w, left + (w->left - left), top, width - (w->left - left), height);
+ DoSetViewportPosition(wz, left, top, w->left - left, height);
+ DoSetViewportPosition(wz, left + (w->left - left), top, width - (w->left - left), height);
return;
}
if (left + width > w->left + w->width) {
- DoSetViewportPosition(w, left, top, (w->left + w->width - left), height);
- DoSetViewportPosition(w, left + (w->left + w->width - left), top, width - (w->left + w->width - left) , height);
+ DoSetViewportPosition(wz, left, top, (w->left + w->width - left), height);
+ DoSetViewportPosition(wz, left + (w->left + w->width - left), top, width - (w->left + w->width - left) , height);
return;
}
if (top < w->top) {
- DoSetViewportPosition(w, left, top, width, (w->top - top));
- DoSetViewportPosition(w, left, top + (w->top - top), width, height - (w->top - top));
+ DoSetViewportPosition(wz, left, top, width, (w->top - top));
+ DoSetViewportPosition(wz, left, top + (w->top - top), width, height - (w->top - top));
return;
}
if (top + height > w->top + w->height) {
- DoSetViewportPosition(w, left, top, width, (w->top + w->height - top));
- DoSetViewportPosition(w, left, top + (w->top + w->height - top), width , height - (w->top + w->height - top));
+ DoSetViewportPosition(wz, left, top, width, (w->top + w->height - top));
+ DoSetViewportPosition(wz, left, top + (w->top + w->height - top), width , height - (w->top + w->height - top));
return;
}
@@ -294,7 +297,7 @@ static void SetViewportPosition(Window *w, int x, int y)
i = top + height - _screen.height;
if (i >= 0) height -= i;
- if (height > 0) DoSetViewportPosition(w + 1, left, top, width, height);
+ if (height > 0) DoSetViewportPosition(FindWindowZPosition(w) + 1, left, top, width, height);
}
}