@@ -6164,39 +6164,37 @@ bool SDL_SetWindowMenuBar(SDL_Window* window, SDL_MenuItem* menu_bar)
61646164 if (!_this ) {
61656165 return SDL_UninitializedVideo ();
61666166 }
6167-
6168- // Same Window/MenuBar combination, no need to do anything.
6169- if (menu_bar -> menu_bar .window == window ) {
6170- return true;
6171- }
61726167
61736168 // Passed NULL to the Window, user wants to retake ownership of the menubar.
61746169 if (!menu_bar && window -> menu_bar ) {
6175- bool success = _this -> SetWindowMenuBar (NULL );
6170+ bool success = _this -> SetWindowMenuBar (window , NULL );
61766171
61776172 SDL_SetObjectValid (window -> menu_bar , SDL_OBJECT_TYPE_MENUBAR , true);
61786173 window -> menu_bar = NULL ;
61796174
61806175 return success ;
61816176 }
61826177
6178+ // Same Window/MenuBar combination, no need to do anything.
6179+ if (menu_bar -> menu_bar .window == window ) {
6180+ return true;
6181+ }
6182+
61836183 if (menu_bar -> common .type != SDL_MENUITEM_MENUBAR ) {
61846184 SDL_SetError ("Can't set menu Item that isn't a Menu onto a Window." );
61856185 return false;
61866186 }
6187-
6187+
6188+ // menu_bar is already on another window, null out the menubar on that window
6189+ // before we add this menubar to the given window.
61886190 if (menu_bar -> menu_bar .window ) {
6189- bool success = _this -> SetWindowMenuBar (NULL );
6190- SDL_SetObjectValid (menu_bar -> menu_bar .window -> menu_bar , SDL_OBJECT_TYPE_MENUBAR , true);
6191- window -> menu_bar = NULL ;
6192- menu_bar -> menu_bar .window -> menu_bar
6193-
6194- menu_bar -> menu_bar .window = NULL ;
6191+ _this -> SetWindowMenuBar (menu_bar -> menu_bar .window , NULL );
61956192 }
61966193
61976194 SDL_MenuBar * menu_bar_real = (SDL_MenuBar * )menu_bar ;
61986195 menu_bar_real -> window = window ;
61996196
6197+ // Window has an existing MenuBar, release it back to the user.
62006198 if (window -> menu_bar ) {
62016199 SDL_SetObjectValid (window -> menu_bar , SDL_OBJECT_TYPE_MENUBAR , true);
62026200 }
@@ -6205,7 +6203,7 @@ bool SDL_SetWindowMenuBar(SDL_Window* window, SDL_MenuItem* menu_bar)
62056203
62066204 SDL_SetObjectValid (menu_bar_real , SDL_OBJECT_TYPE_MENUBAR , false);
62076205
6208- return _this -> SetWindowMenuBar (menu_bar_real );
6206+ return _this -> SetWindowMenuBar (window , menu_bar_real );
62096207}
62106208
62116209void SDL_CleanupMenubars ()
0 commit comments