set parent not working?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
nathanf534
Posts: 199
Joined: Tue Dec 09, 2008 2:55 am

set parent not working?

Post by nathanf534 »

Code:

Code: Select all


IMeshSceneNode* baseNode = smgr->addMeshSceneNode(smgr->getMesh("data/base.b3d"));
....
IMeshSceneNode* flagNode = smgr->addMeshSceneNode(smgr->getMesh("data/flag.b3d"));
....
flagNode->setParent(baseNode);
cout<<"baseNode:"<<baseNode<<endl;
cout<<"flagNode:"<<flagNode<<endl;
cout<<"ParentTest:"<<flagNode->getParent()<<endl;
Output:

Code: Select all

baseNode:0x2219a78
flagNode:0x2219be0
ParentTest:0
I set the parent, but a call to getParent still returns null.


I tried to step through this with a debugger, but at the line,

Code: Select all

flagNode->setParent(baseNode);
I get the error: warning: RTTI symbol not found for class 'irr::scene::CMeshSceneNode'

so it wouldn't let me step into that method and see what it was doing, but after that line, the "Parent" instance variable in flagNode is still NULL.


EDIT: If anyone knows why they debugger wouldn't let me step into that method, I would appreciate it. I have no idea what an RTTI symbol is, so Im not sure if thats the reason.

EDIT2: after further investigation, I have determined the function

Code: Select all

virtual void setParent(ISceneNode* newParent)
in ISceneNode.h is not being called, and it is not defined in IMeshSceneNode.h or CMeshSceneNode.h, so I have no idea what is happening on that line.



Here is a short test, can someone else confirm you get similar output?

Code: Select all

int width=800;
int height=600;
SIrrlichtCreationParameters params;
params.AntiAlias=0;
params.Bits=32;
params.DriverType=EDT_OPENGL;
params.Vsync=true;
params.WindowSize=dimension2d<u32>(width,height);
params.Fullscreen=false;
irrDevice=createDeviceEx(params);
smgr = irrDevice->getSceneManager();
ISceneNode* baseNode = smgr->addCubeSceneNode();
ISceneNode* flagNode = smgr->addCubeSceneNode();
flagNode->setParent(baseNode);
cout<<"baseNode:"<<baseNode<<endl;
cout<<"flagNode:"<<flagNode<<endl;
cout<<"ParentTest:"<<flagNode->getParent()<<endl;
while(signatureEmpty){cout<<wittyComment();}
nathanf534
Posts: 199
Joined: Tue Dec 09, 2008 2:55 am

Post by nathanf534 »

It seems to set the children of the parent correctly, but the parent of the child isn't set. Manually setting the Parent (I had to edit ISceneNode.h since Parent was protected) makes everything work, so I am fairly certain this is a bug in Irrlicht.

I added this after setParent()

Code: Select all

flagNode->Parent=baseNode;
while(signatureEmpty){cout<<wittyComment();}
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

This is the code from ISceneNode:

Code: Select all

		virtual void setParent(ISceneNode* newParent)
		{
			grab();
			remove();

			Parent = newParent;

			if (Parent)
				Parent->addChild(this);

			drop();
		}
As you can see, Parent is set to the proper value. And there's almost no way around.
CuteAlien
Admin
Posts: 9933
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

I had similar errors in the past and it was usually because of a messed up pointer. But can't tell if that's the case here. setParent is fine, I don't think you should change that, the problem is likely somewhere else.

First of all - check the output in the debug-console if there are any warnings, for example for mismatched headers/dll? (if you worked with different Irrlicht version you might have an old dll on your system which is found)

Then - do you do anything special, for example using a custom b3d loader?

If you compile the examples - do those work on your system?
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
nathanf534
Posts: 199
Joined: Tue Dec 09, 2008 2:55 am

Post by nathanf534 »

It turns out this was caused by me adding a variable to the ISceneNode class. I added the line

Code: Select all

void* userData;
at the beginning of the class so I could add data to the nodes for the Physics engine. I am guessing that since I am using the irrlicht library compiled without that, it is messing it up? How else could I add data?
while(signatureEmpty){cout<<wittyComment();}
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

If you make changes to the headers, you have to recompile the engine from scratch. No object file to keep, make clean before. Otherwise, your app will access too far into the class structures, and will get completely wrong results, even though most of the engine will work correctly (as it was compiled before the changes).
Post Reply