Question to Niko's source

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
Peter Müller
Posts: 292
Joined: Sun Mar 14, 2004 5:28 pm
Location: Germany
Contact:

Question to Niko's source

Post by Peter Müller »

Hi!
I read something in Niko's source, what I don't understand:

Code: Select all

00281 {
00282         IGUIButton* button = new CGUIButton(this, parent ? parent : this, id, rectangle);
00283         if (text)
00284                 button->setText(text);
00285         button->drop();
00286         return button;
00287 }
Why is he returning an dropped value?
http://www.games-forge.de - Die Community für Nachwuchsprogrammierer
Celhtar

Post by Celhtar »

I guess for reference counting issues, makes the final drop() at clean-up really deallocate the button
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

Yeah, I was thinking that too. That must be why you can't call a drop() for individual nodes, maybe the individual drop() just stores the fact that it needs to be dealloc'ed when the device is eventually dropped. It would explain a lot I think.
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

Reference counted objects (subclasses of IUnknown) always start with a count of 1.

Gui elements are also being grabbed by their parent (which is in this case the GUIEnvironment itself if you don't specify one). This increments the reference counter to 2.

The mysterious drop brings it back to 1.

They finally get destroyed (death dropped) in the destructor of IGUIElement.
Post Reply