How do I check for a valid node pointer?
How do I check for a valid node pointer?
Hi,
Is there any function that I can use to check whether a node pointer is valid? (ie: points to a complete node)
Is there any function that I can use to check whether a node pointer is valid? (ie: points to a complete node)
Code: Select all
if(node)
{
//do your funky stuff
}
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps
Step back! I have a void pointer, and I'm not afraid to use it!
Height2Normal v. 2.1 - convert height maps to normal maps
Step back! I have a void pointer, and I'm not afraid to use it!
And at least as important - you have to initialize all your pointers with 0 yourself. In c++ you usually do that in the constructor - you initialize all pointers of a class (and usually also all other variables) to 0. This is so important because otherwise your pointers will not be initialized at all and have a random value.ent1ty wrote:off course, when you need a node pointer no more, you have to set it to 0Code: Select all
if(node) { //do your funky stuff }
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
in irrlicht, the engine already initialized the node as 0 by default. so if its an invalid node you will get a zero. so you can do this:
Code: Select all
if (node != 0)
{
//do your stuff
}
My company: http://www.kloena.com
My blog: http://www.zhieng.com
My co-working space: http://www.deskspace.info
My blog: http://www.zhieng.com
My co-working space: http://www.deskspace.info
That's wrong. Actually a software library can't(!) initialize your pointers. How should it do that? Those pointers are in your own code.Virion wrote:in irrlicht, the engine already initialized the node as 0 by default
Initialize your variables in c++ or they will have random values - it does not matter of which type they are.
edit: What Irrlicht often does is to return 0 as value when some function fails. For example if you call addSceneNode() then it will return 0 on failure and if you assign that to a variable it will have a value afterwards. But do not let that stop you from initializing your pointers - it is basically always a very bad idea not doing that. Not doing so will lead to the strangest effects (like code only running in debug...hehe - I just see your other thread)
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
damn. lolCuteAlien wrote:it is basically always a very bad idea not doing that. Not doing so will lead to the strangest effects (like code only running in debug...hehe - I just see your other thread)
My company: http://www.kloena.com
My blog: http://www.zhieng.com
My co-working space: http://www.deskspace.info
My blog: http://www.zhieng.com
My co-working space: http://www.deskspace.info
Obviously, yeah... :\Bate wrote:As far as I know there is no other way to check for a valid pointer except for checking the address.
However, since you can't fully control your pointers, it's maybe more about general design?
Here's how I end my program (in Freebasic):
irrStop (calls various commands in Irrlicht to stop Irrlicht)
system
The system calls all my destructors... since Irrlicht already freed my data (but didn't clear the pointers), the destructors that destroy Irrlicht data would create a segmentation error because they'll be trying to free data that is already freed... only way to fix this atm is to simply remove the Irrlicht-specific destructor. That just gets a bit confusing, though.. what if I want to destroy an object in the middle of my pogram? I need that destructor to stay there!
If the destructor were to stay, I'd have to manually call all the Irrlicht-specific destructors before calling irrStop. Annoying.
ehm, you must not call a destructor on your own !!!agamemnus wrote:The system calls all my destructors
they'll be executed automatically when the instance gets deleted !!!
if you want to clear something manually then best is to create a "cleanup" function and call this, and there delete all the pointers (remove the objects) and then set the pointers to 0...
but never ever call a destructor !!!
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
I think you misunderstand...Acki wrote:ehm, you must not call a destructor on your own !!!agamemnus wrote:The system calls all my destructors
they'll be executed automatically when the instance gets deleted !!!
if you want to clear something manually then best is to create a "cleanup" function and call this, and there delete all the pointers (remove the objects) and then set the pointers to 0...
but never ever call a destructor !!!
I'm talking about my own destructors, not any Irrlicht destructors.
-
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm
hmm, maybe you shouldn't call it "destructor" but "cleanup function" !?!?!agamemnus wrote:I'm talking about my own destructors
constructor/destructor are fixed terms in C++...
a good idea to prevent missunderstandings is to show the code !!!
in this case how your cleanup function and destructor looks like and how/when you call the cleanup...
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java