Page 1 of 1
Correct Way to delete menus.
Posted: Fri Feb 11, 2005 00:51
by Mdobele
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
Re: Correct Way to delete menus.
Posted: Fri Feb 11, 2005 09:56
by CrazyEddie
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
Re: Correct Way to delete menus.
Posted: Tue Feb 15, 2005 17:20
by saetrum
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?
Re: Correct Way to delete menus.
Posted: Tue Feb 15, 2005 19:33
by CrazyEddie
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.
Re: Correct Way to delete menus.
Posted: Tue Feb 15, 2005 20:22
by saetrum
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.
Re: Correct Way to delete menus.
Posted: Wed Feb 16, 2005 09:21
by CrazyEddie
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
Re: Correct Way to delete menus.
Posted: Thu Feb 17, 2005 00:31
by Mdobele
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.