My game's title screen CEGUI menu (window) comes up fine, I click start and go to the gameplay, then I press Escape key to open the in-game menu (also CEGUI), which also loads and shows fine. The problems are: (1) when i click the in-game menu's Quit button and go back to the title screen, the title screen crashes the entire program when it calls loadWindowLayout for the main menu (but it loaded fine the first time); and (2) if i click the in-game menu's continue button, the menu closes like it is supposed to, then when i press escape again, the same code no longer displays the menu.
Here's the CEGUI code in the order that it executes:
1. When my game enters its Title Screen, it executes the following:
Code: Select all
CEGUI::Window* sheet =
CEGUI::WindowManager::getSingleton().loadWindowLayout(
(CEGUI::utf8*)"mainMenu.layout");
GameApp::instance()->getGuiSystem()->setGUISheet(sheet);
CEGUI::WindowManager::getSingleton().getWindow("MainMenu/StartBtn")->
subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&SolidApp::TitleState::onStart, this));
CEGUI::WindowManager::getSingleton().getWindow("MainMenu/ExitBtn")->
subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&SolidApp::TitleState::onExit, this));
2. When it leaves the title screen:
Code: Select all
CEGUI::WindowManager::getSingleton().getWindow("MainMenu")->hide();
GameApp::instance()->getGuiSystem()->setGUISheet(0);
CEGUI::WindowManager::getSingleton().destroyWindow((CEGUI::utf8*)"MainMenu");
3. When it enters the gameplay state, and then the Escape key is pressed, the in-game menu is opened with:
Code: Select all
sheet = CEGUI::WindowManager::getSingleton().loadWindowLayout(
(CEGUI::utf8*)"inGameMenu.layout");
CEGUI::System::getSingleton().setGUISheet(sheet);
CEGUI::WindowManager::getSingleton().getWindow("InGameMenu/ContinueBtn")->
subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&SolidApp::GameplayState::PausedState::onContinue, this));
CEGUI::WindowManager::getSingleton().getWindow("InGameMenu/ExitBtn")->
subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&SolidApp::GameplayState::PausedState::onExit, this));
CEGUI::WindowManager::getSingleton().getWindow("InGameMenu")->show();
4. When the in-game menu is closed by clicking "Continue" or "Quit":
Code: Select all
CEGUI::WindowManager::getSingleton().getWindow("InGameMenu")->hide();
GameApp::instance()->getGuiSystem()->setGUISheet(0);
CEGUI::WindowManager::getSingleton().destroyWindow((CEGUI::utf8*)"InGameMenu");
So then when we go back to the title screen, #1 above is executed and crashes (illegal operation) on the first line's loadWindowLayout call, without throwing either of the exceptions that the method says it throws.
Or, if i click the in-game menu's Continue button instead of Quit, and then open the in-game menu a 2nd time, #3 is of course executed again, but the menu no longer appears (which is why i tried adding the show() call at the end of #3).
I could not find the solutions in the manual or documentation, and haven't found good example code for opening and closing and reopening sheets and windows. Any help is much appreciated.