From 5ae795953afac677134e54f91a11436acb3c969d Mon Sep 17 00:00:00 2001 From: rubidium Date: Thu, 15 May 2008 14:41:56 +0000 Subject: (svn r13104) -Codechange: make ResetObjectToPlace safe to be called recursively via the OnPlaceObjectAbort callback and use this knowledge to simplify closing some windows. --- src/viewport.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/viewport.cpp') diff --git a/src/viewport.cpp b/src/viewport.cpp index 1eb5ec63d..10369e1ec 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -2708,12 +2708,11 @@ void SetObjectToPlaceWnd(CursorID icon, SpriteID pal, ViewportHighlightMode mode void SetObjectToPlace(CursorID icon, SpriteID pal, ViewportHighlightMode mode, WindowClass window_class, WindowNumber window_num) { - Window *w; + Window *w = NULL; /* undo clicking on button and drag & drop */ if (_thd.place_mode != VHM_NONE || _special_mouse_mode == WSM_DRAGDROP) { w = FindWindowById(_thd.window_class, _thd.window_number); - if (w != NULL) w->OnPlaceObjectAbort(); } SetTileSelectSize(1, 1); @@ -2734,10 +2733,16 @@ void SetObjectToPlace(CursorID icon, SpriteID pal, ViewportHighlightMode mode, W if (mode == VHM_SPECIAL) // special tools, like tunnels or docks start with presizing mode VpStartPreSizing(); - if ( (int)icon < 0) + if ((int)icon < 0) { SetAnimatedMouseCursor(_animcursors[~icon]); - else + } else { SetMouseCursor(icon, pal); + } + + /* Call the abort function only *after* the window class/number + * are reset so one doesn't get into infinite loops when someone + * resets the object to place during the abort callback. */ + if (w != NULL) w->OnPlaceObjectAbort(); } void ResetObjectToPlace() -- cgit v1.2.3-54-g00ecf