[fixed]Irrlicht Gui Environment Load Bug

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

[fixed]Irrlicht Gui Environment Load Bug

Post by clarks »

I wrote some piece of code to load a gui from xml into a window. However, whenever I load the gui into the window the elements are not drawn. Neither is the window. But when I load the elements by them selves they are drawn. The window is created using the environment and the root element is the parent. This uses Irrlicht version 1.7.

The following code works but the elements are not drawn.

Code: Select all

irr::gui::IGUIWindow* GuiMachine::Load( const char* file )
{
    // get the screen size
    irr::core::dimension2d<u32> size = mpEnv->getVideoDriver()->getScreenSize();
    irr::core::stringw fileName = file;
 
    // create the window for this gui scene
    irr::gui::IGUIWindow* window = 
        mpEnv->addWindow(irr::core::recti(0,0,640,480),
        false,
        &fileName[0]);
 
    // now load the gui scene
    if( !mpEnv->loadGUI(file,window) ) // failed
    {
        window->remove();
        window->drop();
                printf("failed to load gui scene\n");
        return 0;
    }
 
    printf("window has been created\n");
 
    return window;
}
 
With the following code the elements are drawn, however the window is not the parent

Code: Select all

 
irr::gui::IGUIWindow* GuiMachine::Load( const char* file )
{
    // get the screen size
    irr::core::dimension2d<u32> size = mpEnv->getVideoDriver()->getScreenSize();
    irr::core::stringw fileName = file;
 
    // create the window for this gui scene
    irr::gui::IGUIWindow* window = 
        mpEnv->addWindow(irr::core::recti(0,0,640,480),
        false,
        &fileName[0]);
 
    // now load the gui scene
    if( !mpEnv->loadGUI(file) ) // failed
    {
        window->remove();
        window->drop();
                printf("failed to load gui scene\n");
        return 0;
    }
 
    printf("window has been created\n");
 
    return window;
}
 
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Irrlicht Gui Environment Load Bug

Post by CuteAlien »

I have just added loading and saving to one of my tests, but can't reproduce this (at least not in svn-trunk, can test 1.7 in the evening when I'm done with work): http://ideone.com/tjpFB

There is one problem that saveGui does start saving from the given root-element while loadGUI does start loading into the given root-element (not changing it) - so getting one new root in my test on each run. I'll add an parameter for that I think, but aside from that it works fine.
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
clarks
Posts: 35
Joined: Sat Jul 28, 2012 5:23 am

Re: Irrlicht Gui Environment Load Bug

Post by clarks »

hmmm...
Last edited by clarks on Thu Aug 09, 2012 6:36 pm, edited 1 time in total.
clarks
Posts: 35
Joined: Sat Jul 28, 2012 5:23 am

Re: Irrlicht Gui Environment Load Bug

Post by clarks »

I tested your code with 1.7 and it worked fine. However, when I used one of my xml files it failed. The xml file was created using irr gui tool, so I decided to check this file. In this file there is a tag <irr_gui></irr_gui>. I believe that the gui environment is tripping off of this tag because it does not have an element type. I modified your code to make sure that the elements were being loaded. This was tested by only loading the file itself and not saving it.

Code: Select all

 
case GUI_ID_BUTTON_LOAD:
 ClearAllTestGuiElements(Context);
 Context.device->getGUIEnvironment()->loadGUI("controls.xml", Context.mGuiParent);
 char buf[256];
 sprintf(buf,"The number of children in window: %i\n",(int)Context.mGuiParent->getChildren().getSize());
 Context.device->getLogger()->log(buf);
 break;
 
It tells me that there are fifteen children in the parent. So the file is loading but they elements are not showing. So I believe that the tag <irr_gui></irr_gui> is the problem.
clarks
Posts: 35
Joined: Sat Jul 28, 2012 5:23 am

Re: Irrlicht Gui Environment Load Bug

Post by clarks »

A next interesting thing is that the file saved by irr gui has a section for the gui theme, but the xml file saved from your original code did not have that section.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Irrlicht Gui Environment Load Bug

Post by CuteAlien »

Yeah, that was the problem - thanks for reporting. Loading into a target messed up when the gui-file contained the gui-environment information as well (the skin). I fixed the bug in svn trunk r4272 (I should probably have added it to the 1.7 branch, but my first solution was changing behaviour so I didn't want to risk it, so will only be in Irrlicht 1.8).

But if you start a project now I would recommend anyway using svn trunk already.

Also tried a while until I could figure out a solution for my test-case for saving & loading below a certain element. Found some workaround for that as well:

Code: Select all

 
// move the children from source to target
void MoveChildren(irr::gui::IGUIElement* target, irr::gui::IGUIElement* source)
{
    core::list<IGUIElement*> children = source->getChildren();  // note - no reference, we need a copy here
    for ( core::list<IGUIElement*>::Iterator it = children.begin(); it != children.end();  ++it )
    {
        target->addChild(*it);
    }
}
 
void SaveTextGuiElements(SAppContext & context)
{
    // That line would save the complete gui (for testing to compare results)
    // context.device->getGUIEnvironment()->saveGUI("gui_all_elements.xml");
 
    context.device->getGUIEnvironment()->saveGUI("gui_all_elements.xml", context.mGuiParent);
}
 
void LoadTextGuiElements(SAppContext & context)
{
    context.device->getGUIEnvironment()->loadGUI("gui_all_elements.xml", context.mGuiParent);
    if ( !context.mGuiParent->getChildren().empty() )
    {
        // Workaround because I can't load _into_ an element so far in Irrlicht. So I have now one more copy of 
        // context.mGuiParent below context.mGuiParent which I have to remove again.
        // Irrlicht might change that on loading some day with another paramter (can't easily change it on saving 
        // without changing the format as xml-files need a single root).
        // First element is our dummy, remove that from the hierarchy.
        IGUIElement * dummy = *(context.mGuiParent->getChildren().begin());
        MoveChildren(context.mGuiParent, dummy);
        dummy->remove();
    }
}
 
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