Taking care of keeping things mostly up-to-date
[freeglut] / src / freeglut_structure.c
index da29757..9c515c8 100644 (file)
@@ -168,7 +168,7 @@ SFG_Menu* fgCreateMenu( FGCBmenu menuCallback )
     fgState.BuildingAMenu = FALSE ;
 
     glutHideWindow () ;  /* Hide the window for now */
-    fgStructure.Window = current_window ;
+    fgSetWindow ( current_window ) ;
 
     /*
      * Initialize the object properties:
@@ -296,9 +296,9 @@ void fgDestroyWindow( SFG_Window* window, GLboolean needToClose )
     if ( window->Callbacks.Destroy != NULL )
     {
       SFG_Window *activeWindow = fgStructure.Window ;
-      fgStructure.Window = window ;
+      fgSetWindow ( window ) ;
       window->Callbacks.Destroy () ;
-      fgStructure.Window = activeWindow ;
+      fgSetWindow ( activeWindow ) ;
     }
 
     /*
@@ -321,6 +321,7 @@ void fgDestroyWindow( SFG_Window* window, GLboolean needToClose )
      * have everything inside it freed and we do not have to care...
      */
     free( window );
+    if ( fgStructure.Window == window ) fgStructure.Window = NULL ;
 }
 
 /*
@@ -432,6 +433,9 @@ void fgDestroyMenu( SFG_Menu* menu )
   /*
    * Destroy the window associated with the menu
    */
+  if ( fgStructure.Window == menu->Window )
+    fgSetWindow ( menu->ParentWindow ) ;
+
   fgDestroyWindow ( menu->Window, TRUE ) ;
 
   /*
@@ -486,11 +490,11 @@ void fgDestroyStructure( void )
   /*
    * Make sure all windows and menus have been deallocated
    */
-  while( (window = (SFG_Window *)fgStructure.Windows.First) != NULL )
-    fgDestroyWindow( window, TRUE );
-
   while( (menu = (SFG_Menu *)fgStructure.Menus.First) != NULL )
     fgDestroyMenu( menu );
+
+  while( (window = (SFG_Window *)fgStructure.Windows.First) != NULL )
+    fgDestroyWindow( window, TRUE );
 }
 
 /*