]> granicus.if.org Git - nethack/commitdiff
(from <Someone>)
authornethack.allison <nethack.allison>
Mon, 11 Mar 2002 04:36:54 +0000 (04:36 +0000)
committernethack.allison <nethack.allison>
Mon, 11 Mar 2002 04:36:54 +0000 (04:36 +0000)
Fix crash.
WIN_MAP was used without before initialization in mswin_select_map_mode

win/win32/mhmain.c
win/win32/mhmap.c
win/win32/mswproc.c

index 54aa4b019bb8a2eef45a4cf9a0a0adcfe8706c76..e3a83af51cd58258ac31ab1df5cccbae8dfa9eb1 100644 (file)
@@ -829,6 +829,9 @@ void mswin_menu_check_intf_mode()
 void mswin_select_map_mode(int mode)
 {
        PNHMainWindow  data;
+       winid map_id;
+
+       map_id = WIN_MAP;
        data = (PNHMainWindow)GetWindowLong(GetNHApp()->hMainWnd, GWL_USERDATA);
 
        /* override for Rogue level */
@@ -866,7 +869,15 @@ void mswin_select_map_mode(int mode)
        }
 
        iflags.wc_map_mode = mode;
-       mswin_map_mode(mswin_hwnd_from_winid(WIN_MAP), mode);
+       
+       /* 
+       ** first, check if WIN_MAP has been inialized.
+       ** If not - attempt to retrieve it by type, then check it again
+       */
+       if( map_id==WIN_ERR ) 
+               map_id = mswin_winid_from_type(NHW_MAP);
+       if( map_id!=WIN_ERR )
+               mswin_map_mode(mswin_hwnd_from_winid(map_id), mode);
 }
 
 static struct t_menu2mapmode {
index c1c798332be64fe7e1def9d865d61b0b36873810..8355b16abe3beadcbdc865f38ce9ceb3729adca9 100644 (file)
@@ -178,7 +178,6 @@ int mswin_map_mode(HWND hWnd, int mode)
        SIZE mapSize;
 
        data = (PNHMapWindow)GetWindowLong(hWnd, GWL_USERDATA);
-       if (!data) return mode;
        if( mode == data->mapMode ) return mode;
        
        oldMode = data->mapMode;
index 0862ca3f9d3bea6318181e2d39318386fb56f3f6..1bb43540976169c71ce37efeb02e1330ea15e56f 100644 (file)
@@ -146,6 +146,9 @@ void mswin_init_nhwindows(int* argc, char** argv)
 #endif
     mswin_nh_input_init();
 
+       /* set it to WIN_ERR so we can detect attempts to
+          use this ID before it is inialized */
+       WIN_MAP = WIN_ERR;
 
     /* Read Windows settings from the reqistry */
     mswin_read_reg();
@@ -406,17 +409,19 @@ void mswin_clear_nhwindow(winid wid)
         (wid < MAXWINDOWS) &&
         (GetNHApp()->windowlist[wid].win != NULL))
     {
-         SendMessage( 
-                        GetNHApp()->windowlist[wid].win, 
-                        WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_CLEAR_WINDOW, (LPARAM)NULL );
-    }
-
 #ifdef REINCARNATION
-    if( Is_rogue_level(&u.uz) ) 
-               mswin_map_mode(mswin_hwnd_from_winid(WIN_MAP), ROGUE_LEVEL_MAP_MODE);
-       else 
-               mswin_map_mode(mswin_hwnd_from_winid(WIN_MAP), iflags.wc_map_mode);
+               if( GetNHApp()->windowlist[wid].type == NHW_MAP ) {
+                       if( Is_rogue_level(&u.uz) ) 
+                               mswin_map_mode(mswin_hwnd_from_winid(WIN_MAP), ROGUE_LEVEL_MAP_MODE);
+                       else 
+                               mswin_map_mode(mswin_hwnd_from_winid(WIN_MAP), iflags.wc_map_mode);
+               }
 #endif
+
+               SendMessage( 
+                        GetNHApp()->windowlist[wid].win, 
+                        WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_CLEAR_WINDOW, (LPARAM)NULL );
+       }
 }
 
 /* -- Display the window on the screen.  If there is data