Correct Way to delete menus.

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

User avatar
Mdobele
Just popping in
Just popping in
Posts: 10
Joined: Wed Jan 12, 2005 12:06
Location: Brisbane / Australia
Contact:

Correct Way to delete menus.

Postby Mdobele » Fri Feb 11, 2005 00:51

Hi.

I'm just wondering as to the correct way to clean up my menu systems. Lets say I have one main "Sheet" that is used by all my menu boxes. Each menu box is its own window and has a few buttons with events on them. What is the correct way to remove that window/button/event from the system so that it can be used again. All the demos simply delete the entire system in one line.

Thanks
Visit the PrimdGames website
www.primedgames.com

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

Re: Correct Way to delete menus.

Postby CrazyEddie » Fri Feb 11, 2005 09:56

If you mean remove to be re-added later then just call removeChild(menuBox) on the window where the menu box is attached, and later use addChild to add it back.

If you want to completely destroy the menu box, but not the parent sheet and its other attached windows, then remove the menu as described above and use WindowManager to just destoy that window (and, by deafault, it's children).

Currently you need to be careful destroying windows from event handlers of the window being destroyed, if you're going to do this then you'll need to maintain a 'dead pool' where the actual destruction is not done until you're outside the event handlers. This is something that I will be incorporating into the system shortly.

CE

User avatar
saetrum
Quite a regular
Quite a regular
Posts: 55
Joined: Wed Jan 12, 2005 12:06
Location: Albuquerque, NM USA

Re: Correct Way to delete menus.

Postby saetrum » Tue Feb 15, 2005 17:20

I'm trying to understand when I need to destroy a window or when the system does it for me. Here is my constructor and destructor. This causes an exception on program exit

Code: Select all

//Constructor
MainMenuState::MainMenuState(SceneManager* sm, CEGUI::Renderer* renderer, CEGUI::System* gui_system)
:State(sm, renderer, gui_system)
{

   // load scheme and set up defaults
   CEGUI::SchemeManager::getSingleton().loadScheme(
      (CEGUI::utf8*)"TaharezLook.scheme");
   mGUISystem->setDefaultMouseCursor(
      (CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow");
   mGUISystem->setDefaultFont((CEGUI::utf8*)"Tahoma-12");

   CEGUI::Window* sheet =
      CEGUI::WindowManager::getSingleton().loadWindowLayout(
      (CEGUI::utf8*)"MainMenu.layout");
   mGUISystem->setGUISheet(sheet);

   CEGUI::Texture* myTexture = mGUIRenderer->createTexture("greenbg.jpg");
   CEGUI::Imageset* pImageSet = CEGUI::ImagesetManager::getSingleton().createImageset("background", myTexture);
   pImageSet->defineImage("bg", CEGUI::Point(0.0f, 0.0f),CEGUI::Size(1024,1024),CEGUI::Point(0.0f,0.0f));

   CEGUI::StaticImage* si = (CEGUI::StaticImage*)CEGUI::WindowManager::getSingleton().getWindow("Background");
   si->setPosition(CEGUI::Point(0.0f, 0.0f));
   si->setSize(CEGUI::Size(1.0f, 1.0f));
   si->setImage("background","bg");
   si->setFrameEnabled(false);
   si->setBackgroundEnabled(true);


   setupEventHandlers();
}
MainMenuState::~MainMenuState()
{

   CEGUI::WindowManager::getSingleton().destroyWindow("MainMenu");
   //CEGUI::Imageset* pImageSet= CEGUI::ImagesetManager::getSingleton().getImageset("background");
//   CEGUI::ImagesetManager::getSingleton().destroyImageset(pImageSet);

}


When I try to destroy the window in the destructor, the program is not happy. If I don't destroy it, I feel as if I'm not cleaning up. Does the System destroy the currently active Window?
There are 10 types of people in the world: those that understand binary and those that don't.

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

Re: Correct Way to delete menus.

Postby CrazyEddie » Tue Feb 15, 2005 19:33

The things created by the system are mostly managed by the system. This basically means anything created via some *Magager object will automatically be cleaned up when the System is destroyed. Textures not cleaned up by any other operation are cleaned up when the renderer is destroyed.

Having said the above, your code should really work. Can you post the contents of CEGUI.log when you get the exception.

Thanks,

CE.

User avatar
saetrum
Quite a regular
Quite a regular
Posts: 55
Joined: Wed Jan 12, 2005 12:06
Location: Albuquerque, NM USA

Re: Correct Way to delete menus.

Postby saetrum » Tue Feb 15, 2005 20:22

CE,

Here's the log

Code: Select all

15/02/2005 20:15:54 (InfL1)   ---- Successfully completed loading of GUI layout from 'MainMenu.layout' ----
15/02/2005 20:15:54 (InfL1)   Attempting to create Imageset 'background' with texture only.
15/02/2005 20:16:03 (InfL1)   ---- Begining CEGUI System destruction ----
15/02/2005 20:16:03 (InfL2)   Window 'Background' has been destroyed.


Unfortunately, it's not real helpful. It looks like the exception isn't being thrown by CEGUI. I'll have to explore a little more.
There are 10 types of people in the world: those that understand binary and those that don't.

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

Re: Correct Way to delete menus.

Postby CrazyEddie » Wed Feb 16, 2005 09:21

Is it possible that the MainMenuState object is outliving the gui system itself? This would cause issues with non-existant singletons (asserts) and possibly other issues too.

CE

User avatar
Mdobele
Just popping in
Just popping in
Posts: 10
Joined: Wed Jan 12, 2005 12:06
Location: Brisbane / Australia
Contact:

Re: Correct Way to delete menus.

Postby Mdobele » Thu Feb 17, 2005 00:31

Thanks for the answer. I was indeed trying to delete my menus whilst still running through the event handler. Having a "dead pool" has solved the problem fine.
Visit the PrimdGames website

www.primedgames.com


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 8 guests