creating an empty parent node for GUI elements

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
Isometric God
Posts: 69
Joined: Sun Oct 12, 2003 3:42 pm
Location: Germany

creating an empty parent node for GUI elements

Post by Isometric God »

hey,
I want to create an empty parent node for every "page" of my menu screen. What I do is this :

Code: Select all

	parent = new gui::IGUIElement(gui::EGUIET_ELEMENT, env, gui_root, menu_id, screen_rect);
	parent->drop();
	parent->setVisible(false);
it works and the ref.counter is 1 at this point here, but the parent is -NOT- deleted when the app. exits causing a mem leak. anyone got an idea? thanks
Saku
Posts: 158
Joined: Wed Jan 05, 2005 8:48 am
Location: Denmark

Post by Saku »

I dont think you are supposed to "setVisible();" after you dropped it.
Try the other way around and maybe something like this:

Code: Select all

// Clean up the xml parser after usage
xmlReader->drop();
xmlReader = 0;
delete xmlReader;
..that my own code so you ofcourse have to modiy it :roll:
Call me Wice, Miami Wice!
Frodenius
Posts: 64
Joined: Sun Aug 29, 2004 11:24 am
Location: Germany/Frankfurt
Contact:

Post by Frodenius »

well... if you set the pointer to NULL, nothing will be deleted.
and you are definitely allowed to call setVisible after having dropped the object.
@isogod:
how do you know the object is not destroyed at the end?
i do it the same way and never noticed mem leaks.
worst programming style ever seen...
Frodenius
Posts: 64
Joined: Sun Aug 29, 2004 11:24 am
Location: Germany/Frankfurt
Contact:

Post by Frodenius »

*sigh* i had a look into the doc, and, wow suprise, iguienvironment is derived from iguielement, means it is the root node itself, and if a guielement is destroyed, it drops its children.

http://irrlicht.sourceforge.net/docu/_i ... tml#l00049

if the refcounter is 1 after you created and dropped the object once, it should be destroyed when the environment is.
worst programming style ever seen...
Isometric God
Posts: 69
Joined: Sun Oct 12, 2003 3:42 pm
Location: Germany

Post by Isometric God »

exactly, but it definitly isn´t. I set the debug flag ( only working on M$ compilers ).

Code: Select all

#include <crtdbg.h>

...

_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

It works just fine here... I get no leak messages. If you wanted to verify that everything gets cleaned up, set a breakpoint in the IGUIElement destructor. You would hit the breakpoint twice [once for the environment and once for the empty element].

It sounds like you are holding a reference to the element somewhere else and that is preventing it from being deleted when the environment is cleaned up.

Code: Select all

int main(int argc, char* argv[])
{
  _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);

  // create device and exit if creation failed
  Device = createDevice(EDT_DIRECT3D9, core::dimension2d<s32>(800, 600),
      16, false, false, false);

  IGUIEnvironment* Environ = Device->getGUIEnvironment();

  IGUIElement* Element = new IGUIElement(EGUIET_ELEMENT,
      Environ, Environ->getRootGUIElement(), -1, core::rect<s32>(0, 0, 100, 100));
  Element->drop();
  Element->setVisible(false);

  Device->drop();
  return 0;
}
Isometric God
Posts: 69
Joined: Sun Oct 12, 2003 3:42 pm
Location: Germany

Post by Isometric God »

Got it !

Code: Select all

Device->drop(); 
I don´t know how that issue is related with the memory leak, but it helped :)
Thanks a lot
Frodenius
Posts: 64
Joined: Sun Aug 29, 2004 11:24 am
Location: Germany/Frankfurt
Contact:

Post by Frodenius »

:D lol stinkin stupid :D
forgot to drop the device... mama!! ;)
worst programming style ever seen...
JeffL
Competition winner
Posts: 14
Joined: Wed Dec 14, 2005 10:42 am
Location: San Jose, CA
Contact:

Post by JeffL »

Why do you do

Code: Select all

Element->drop()
just before setVisible? Won't Device->drop() automatically drop the element since the IGUIElement is a child?

I apologize if this question is really noobish.

- Jeff
Post Reply