Crash or malfunction on Loading Windows the 2nd time.

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

pianoman
Just popping in
Just popping in
Posts: 12
Joined: Fri Mar 20, 2009 23:22
Location: Nebraska, USA

Crash or malfunction on Loading Windows the 2nd time.

Postby pianoman » Fri Mar 20, 2009 23:32

Hello. I'm using CEGUI with Ogre and am having two CEGUI problems, both related to CEGUI state apparently, because both work the first time but then not the second time.

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.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Sat Mar 21, 2009 14:34

Hi, and welcome :)

When you get the 'crashes' what is the specific exception and what does tha callstack look like (debug mode)?

Are there errors in the CEGUI.log file for each of the issue cases?

On those lines where you set the layout back to 0 and then destroy a named window, is that named window the root of the layout, or do the layouts all contain a 'root' window?

CE.

pianoman
Just popping in
Just popping in
Posts: 12
Joined: Fri Mar 20, 2009 23:22
Location: Nebraska, USA

Postby pianoman » Sat Mar 21, 2009 19:25

Thanks for the welcome, and this gui system is awesome! I just need to use it right... :oops:

The error shown when the program crashes is the typical Windows Vista "Solid.exe has stopped working" which doesn't help much, and unfortunately I can't even get a call stack in debug mode (probably because Eclipse CDT's GDB interface is stinky, though I'm won't complain too much since it's open source and free), but the CEGUI log that you mentioned does help. After the standard factory setup logs it has:

Code: Select all

20/03/2009 16:23:26 (InfL1)   ---- Successfully completed loading of GUI layout from 'mainMenu.layout' ----
20/03/2009 16:23:26 (InfL1)   Attempting to create Imageset 'BlueHighway-12_auto_glyph_images_ ' with texture only.
20/03/2009 16:23:33 (InfL1)   ---- Successfully completed loading of GUI layout from 'inGameMenu.layout' ----
20/03/2009 16:23:35 (Error)   Exception: WindowManager::createWindow - A Window object with the name 'root' already exists within the system.
20/03/2009 16:23:35 (Error)   Exception: GUILayout_xmlHandler::startElement - layout loading has been aborted since Window named 'root' already exists.
20/03/2009 16:23:35 (Error)   WindowManager::loadWindowLayout - loading of layout from file 'mainMenu.layout' failed.


Those exceptions apparently happen for the 2nd load of 'mainMenu.layout' right? So apparently I'm making the mistake of trying to load the same root window of mainMenu.layout twice.

So for me it comes down to how one should set up root windows and child windows when he wants to load and destroy different windows multiple times. Always use the same root and don't define a root in the mainMenu or inGameMenu layouts?

Here's mainMenu.layout:

Code: Select all

<?xml version="1.0" ?>
<GUILayout>
<Window Type="DefaultGUISheet" Name="root">
   <Window Type="DefaultGUISheet" Name="MainMenu">
      <Property Name="AlwaysOnTop" Value="True" />
      <!-- <Property Name="Disabled" Value="True" /> -->
      <Property Name="UnifiedPosition" Value="{{0.375,0},{0.5,0}}" />
      <Property Name="UnifiedSize" Value="{{0.25,0},{0.5,0}}" />
      
        <Property Name="Text" Value="File" />
        <Window Type="TaharezLook/Button" Name="MainMenu/StartBtn">
            <Property Name="UnifiedPosition" Value="{{0.1,0},{0.1,0}}" />
            <Property Name="UnifiedSize" Value="{{0.8,0},{0.07,0}}" />
            <Property Name="Text" Value="Start" />
        </Window>
        <Window Type="TaharezLook/Button" Name="MainMenu/OptionsBtn">
            <Property Name="UnifiedPosition" Value="{{0.1,0},{0.2,0}}" />
            <Property Name="UnifiedSize" Value="{{0.8,0},{0.07,0}}" />
            <Property Name="Text" Value="Options" />
        </Window>
        <Window Type="TaharezLook/Button" Name="MainMenu/ExitBtn">
            <Property Name="UnifiedPosition" Value="{{0.1,0},{0.3,0}}" />
            <Property Name="UnifiedSize" Value="{{0.8,0},{0.07,0}}" />
            <Property Name="Text" Value="Exit" />
        </Window>
   </Window>
</Window>
</GUILayout>

And inGameMenu.layout:

Code: Select all

<?xml version="1.0" ?>

<GUILayout>
<Window Type="DefaultGUISheet" Name="inGameMenuRoot">
   <Window Type="DefaultGUISheet" Name="InGameMenu">
      <Property Name="AlwaysOnTop" Value="True" />
      <Property Name="UnifiedPosition" Value="{{0.375,0},{0.5,0}}" />
      <Property Name="UnifiedSize" Value="{{0.25,0},{0.5,0}}" />
      
        <Property Name="Text" Value="File" />
        <Window Type="TaharezLook/Button" Name="InGameMenu/ContinueBtn">
            <Property Name="UnifiedPosition" Value="{{0.1,0},{0.1,0}}" />
            <Property Name="UnifiedSize" Value="{{0.8,0},{0.07,0}}" />
            <Property Name="Text" Value="Continue" />
        </Window>
        <Window Type="TaharezLook/Button" Name="InGameMenu/OptionsBtn">
            <Property Name="UnifiedPosition" Value="{{0.1,0},{0.2,0}}" />
            <Property Name="UnifiedSize" Value="{{0.8,0},{0.07,0}}" />
            <Property Name="Text" Value="Options" />
        </Window>
        <Window Type="TaharezLook/Button" Name="InGameMenu/ExitBtn">
            <Property Name="UnifiedPosition" Value="{{0.1,0},{0.3,0}}" />
            <Property Name="UnifiedSize" Value="{{0.8,0},{0.07,0}}" />
            <Property Name="Text" Value="Quit" />
        </Window>
   </Window>
</Window>
</GUILayout>

pianoman
Just popping in
Just popping in
Posts: 12
Joined: Fri Mar 20, 2009 23:22
Location: Nebraska, USA

Postby pianoman » Sat Mar 21, 2009 19:34

I just tried destroying the root windows when leaving both the main menu and the in game menu, and sure enough it worked! (silly me)

But now what I wonder is, can a person keep the same root window so he could add/remove different windows? (Like an app with tool windows and consoles, etc) I would guess this would require not defining a root window in the .layout files; can you do that?

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Sat Mar 21, 2009 23:22

A 'technically correct' layout may only have a single window at the base level, although this does not have to be a DefaultWindow such as what is typically used for a 'root' window - it could be a main dialog window or whatever. In these cases you can add the window returned from the loadWindowLayout function as a child of the current GUI sheet, and later detach it and destroy it (or just keep it around for later use / reattachment).

You could keep the DefaultWindow 'root' elements, though obviously you need to avoid name collisions (one option is to leave the name empty, though that's cheating and can cause other hard-to-debug issues if you're not careful!!). You can also add full-sized roots to other full-sized roots, though in those cases use of the "MousePassThroughEnabled" property will be required to allow mouse input to reach content that may be beneath the transparent root window(s).

CE.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 17 guests