[nasty bug] UI Elements still activated when hidden.

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
clarks
Posts: 35
Joined: Sat Jul 28, 2012 5:23 am

[nasty bug] UI Elements still activated when hidden.

Post by clarks »

GUI elements can still recieve keyboard input even when hidden. This is a nasty bug as it caused my application to duplicate a whole game level. I confirmed it with example five from irrlicht tutorials. When GUI_ID_NEW_WINDOW_BUTTON is pressed, the first time it is hidden and a new window is created. However, once hidden pressing the enter key will still create more windows by activating the button. Modifying irrlicht example 5 with the following code in event receiver will produce the bug.

Code: Select all

 
                case GUI_ID_NEW_WINDOW_BUTTON:
                    {
                        // this is where the beauty happens, even a hidden button gets activated
                        event.GUIEvent.Caller->setVisible(false);
 
                    Context.listbox->addItem(L"Window created");
                    Context.counter += 30;
                    if (Context.counter > 200)
                        Context.counter = 0;
 
                    IGUIWindow* window = env->addWindow(
                        rect<s32>(100 + Context.counter, 100 + Context.counter, 300 + Context.counter, 200 + Context.counter),
                        false, // modal?
                        L"Test window");
 
                    env->addStaticText(L"Please close me",
                        rect<s32>(35,35,140,50),
                        true, // border?
                        false, // wordwrap?
                        window);
                    }
                    return true;
 
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: [nasty bug] UI Elements still activated when hidden.

Post by CuteAlien »

Ok, first quick workaround, call environment->setFocus(0) as well there and it will work. The problem is that the element is still focused.

Unfortunately there is no quick workaround without rewriting focus-behavior in Irrlicht a lot. For example you can also set the parent invisible and also the function used for setVisible is virtual meaning each gui-element could overwrite it anywa. Also the exact same problem is also in remove - even a removed element can still have the focus. And lastly it's not really clear if an invisible element should be able to receive events or not. I think in other gui-libraries they still can receive events - so focus is seperate from visibility (at least I remember one game using invisible MFC-elements for the button behavior and then just drawing textures over those places).

The problem is that this stuff never really got defined in Irrlicht. It's a really big todo, but as there are workaround that task just never made it to the top of my todo list.
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
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: [nasty bug] UI Elements still activated when hidden.

Post by Mel »

That is why i don't hide windows and such, when using the GUI elements. If i close the window, i destroy it completely, after, if i need it again, i recreate it. Also, i use some boolean guards so i don't create the windows twice. I don't know if this may help, but it is a simple workaround
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: [nasty bug] UI Elements still activated when hidden.

Post by CuteAlien »

I do work with hiding. Setting the focus to 0 is sufficient.
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
Post Reply