device-run() issue when switching GUI

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
thefuzion
Posts: 10
Joined: Tue Mar 06, 2007 11:31 am

device-run() issue when switching GUI

Post by thefuzion »

Hi,

I'm having troubles to write a clean and safe function that switches between two GUIs.
I precise that my program is NOT multithreaded. And I use only Irrlicht to handle inputs/GUI events.

I have something like that :

Code: Select all

// clear current GUI
device->clearSystemMessages();
device->setEventReceiver(NULL);
const core::list<IGUIElement*>& children = env->getRootGUIElement()->getChildren();
while (!children.empty())
	(*children.getLast())->remove();

// create new GUI
gui::IGUIContextMenu* menu = env->addMenu();
menu->addItem(L"File", -1, true, true);
...
add other GUI stuff
...
device->clearSystemMessages();
device->setEventReceiver(this->er);
I though it was quite clean but i'm getting an exception (sometimes only) when I switch GUIs. The exception is detected by the debugger on the line "while(device->run())". It seems that this is about events because the more I press keys or other inputs during the switch, the more I have chance to get the exception.

Also, sometimes it doesn't throw any exception but the new created GUI is built partially only... This is very weird. :?

Has anyone an idea about how to solve this problem ?

Thanks in advance!
CuteAlien
Admin
Posts: 10021
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

did you try just calling clear() for the gui-environment instead of manually removing the gui-elements? It does some more things - it also makes sure the hovered and the focused element get cleaned up.

If that still doesn't work, it would help to have a complete example to reproduce this bug.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
thefuzion
Posts: 10
Joined: Tue Mar 06, 2007 11:31 am

Post by thefuzion »

Thanks for reply,

I tried env->clear() but it was even worse as it made it fail almost all the time (the exception occurred more often).

It seems I have just solved my problem by removing only what I strictly needed to remove. Thus, I am not removing anymore the Menu and the Toolbar them-self. I don't know why, but it seems that Irrlicht doesn't like when you remove a Menu and/or a Toolbar and then create a new one...
It's weird, but i'm quite sure this was the problem.

It would be long for me to do a little program which reproduces exactly the same bug, and I really don't have time currently. I'll try to make something later if you want.
thefuzion
Posts: 10
Joined: Tue Mar 06, 2007 11:31 am

Post by thefuzion »

No it wasn't that. I don't have the problem anymore but I remove the menu and the toolbar...
Post Reply