- SFG_Window *window;
- SFG_Menu *from;
- SFG_MenuEntry *entry;
-
- assert( menu != NULL );
- freeglut_assert_ready;
-
- /*
- * First of all, have all references to this menu removed from all windows:
- */
- for( window = fgStructure.Windows.First; window; window = window->Node.Next )
- {
- fghRemoveMenuFromWindow( window, menu );
- }
-
- /*
- * Now proceed with removing menu entries that lead to this menu
- */
- for( from = fgStructure.Menus.First; from; from = from->Node.Next )
- {
- fghRemoveMenuFromMenu( from, menu );
- }
-
- /*
- * If the programmer defined a destroy callback, call it
- * A. Donev: But first make this the active menu
- */
- if ( menu->Destroy != NULL )
- {
- SFG_Menu *activeMenu=fgStructure.Menu;
- fgStructure.Menu = menu;
- menu->Destroy () ;
- fgStructure.Menu = activeMenu;
- }
-
- /*
- * Now we are pretty sure the menu is not used anywhere
- * and that we can remove all of its entries
- */
- while( (entry = menu->Entries.First) != NULL )
- {
- fgListRemove(&menu->Entries, &entry->Node);
+ SFG_Window *window;
+ SFG_Menu *from;
+
+ FREEGLUT_INTERNAL_ERROR_EXIT ( menu, "Menu destroy function called with null menu",
+ "fgDestroyMenu" );
+
+ /* First of all, have all references to this menu removed from all windows: */
+ for( window = (SFG_Window *)fgStructure.Windows.First;
+ window;
+ window = (SFG_Window *)window->Node.Next )
+ fghRemoveMenuFromWindow( window, menu );
+
+ /* Now proceed with removing menu entries that lead to this menu */
+ for( from = ( SFG_Menu * )fgStructure.Menus.First;
+ from;
+ from = ( SFG_Menu * )from->Node.Next )
+ fghRemoveMenuFromMenu( from, menu );