diff options
author | Darkvater <darkvater@openttd.org> | 2006-11-18 16:47:02 +0000 |
---|---|---|
committer | Darkvater <darkvater@openttd.org> | 2006-11-18 16:47:02 +0000 |
commit | b3c48c0a84323838b5104e422d11b8a1250325c8 (patch) | |
tree | 8112ec497b55f459780ad628193295c31cabfe28 /vehicle_gui.c | |
parent | aa97b61a27cecfb6e06526fa74d95629cc7259a5 (diff) | |
download | openttd-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 'vehicle_gui.c')
-rw-r--r-- | vehicle_gui.c | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/vehicle_gui.c b/vehicle_gui.c index 849dfb4e6..6ec40f397 100644 --- a/vehicle_gui.c +++ b/vehicle_gui.c @@ -102,32 +102,40 @@ static const StringID _rail_types_list[] = { void RebuildVehicleLists(void) { - Window *w; + Window* const *wz; + + FOR_ALL_WINDOWS(wz) { + Window *w = *wz; - for (w = _windows; w != _last_window; ++w) switch (w->window_class) { - case WC_TRAINS_LIST: case WC_ROADVEH_LIST: - case WC_SHIPS_LIST: case WC_AIRCRAFT_LIST: - WP(w, vehiclelist_d).l.flags |= VL_REBUILD; - SetWindowDirty(w); - break; - default: break; + case WC_TRAINS_LIST: + case WC_ROADVEH_LIST: + case WC_SHIPS_LIST: + case WC_AIRCRAFT_LIST: + WP(w, vehiclelist_d).l.flags |= VL_REBUILD; + SetWindowDirty(w); + break; } + } } void ResortVehicleLists(void) { - Window *w; + Window* const *wz; + + FOR_ALL_WINDOWS(wz) { + Window *w = *wz; - for (w = _windows; w != _last_window; ++w) switch (w->window_class) { - case WC_TRAINS_LIST: case WC_ROADVEH_LIST: - case WC_SHIPS_LIST: case WC_AIRCRAFT_LIST: - WP(w, vehiclelist_d).l.flags |= VL_RESORT; - SetWindowDirty(w); - break; - default: break; + case WC_TRAINS_LIST: + case WC_ROADVEH_LIST: + case WC_SHIPS_LIST: + case WC_AIRCRAFT_LIST: + WP(w, vehiclelist_d).l.flags |= VL_RESORT; + SetWindowDirty(w); + break; } + } } static void BuildVehicleList(vehiclelist_d* vl, PlayerID owner, StationID station, OrderID order, uint16 depot_airport_index, uint16 window_type) |