[Solved] getSceneNodeFromCameraBB() not behaving as expected

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
cat.exe
Posts: 34
Joined: Sat Sep 14, 2013 11:52 pm

[Solved] getSceneNodeFromCameraBB() not behaving as expected

Post by cat.exe »

Hello! Once again, I have a problem I was hoping someone could help with.

This time my question is regarding ISceneCollisionManager::getSceneNodeFromCameraBB(), and selecting nodes. The goal was, in this part of my project, to be able to select an arbitrary node in the scene and have it become wireframe; the selection process is triggered by pointing at a node and right-clicking on the mouse. Nodes are deselected simply by pointing anywhere and clicking (or at another node to deselect and select at the same time.)

The issue is that even when the right mouse button is pressed and the observer is not aiming at a node, getSceneNodeFromCameraBB() seems to not return null. I say this because pointedNode, the variable I have getSceneNodeFromCameraBB() return into, comes up true when checked to ensure it is not null, (in line 9) causing a segmentation fault in line ten where it is accessed.

Code: Select all

 
if (receiver->rightMouseButtonPressed())
{
    scene::ISceneNode* pointedNode = smgr->getSceneCollisionManager()->getSceneNodeFromCameraBB(camera, -1);
 
    if (selected != 0)
        ((scene::IMeshSceneNode*)selected)->getMesh()->setMaterialFlag(video::E_MATERIAL_FLAG::EMF_WIREFRAME, false);
 
    selected = pointedNode;
    if (selected != 0)
        ((scene::IMeshSceneNode*)selected)->getMesh()->setMaterialFlag(video::E_MATERIAL_FLAG::EMF_WIREFRAME, true);
}
 
It is notable that this code does function unless the user tries to deselect a currently selected node by right-clicking in an arbitrary direction.

-Will
Last edited by cat.exe on Wed Mar 19, 2014 3:13 am, edited 1 time in total.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: getSceneNodeFromCameraBB() not behaving as expected

Post by CuteAlien »

Check the type of the node you get. Probably it's not a IMeshSceneNode - my guess would be that you hit the skybox.
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
cat.exe
Posts: 34
Joined: Sat Sep 14, 2013 11:52 pm

Re: getSceneNodeFromCameraBB() not behaving as expected

Post by cat.exe »

Hmm... this is a good suggestion, but I need to know: Could there possibly be a skybox by default in my irr scene? I did not insert one myself (Nor have I ever used one before.)
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: getSceneNodeFromCameraBB() not behaving as expected

Post by CuteAlien »

Irrlicht doesn't add a skybox. If you created your scene with an editor like irrEdit... I have no idea (never used it). But just take a look at the variable in the debugger after it crashed - then you will know within seconds what type of node that really is. That's why we have debuggers :-)
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
cat.exe
Posts: 34
Joined: Sat Sep 14, 2013 11:52 pm

Re: getSceneNodeFromCameraBB() not behaving as expected

Post by cat.exe »

Fixed! The problem did turn out to be related to what type the returned object was (Thanks again, CuteAlien) though I'm still not sure the exact cause. The point is, I fixed it by removing the cast to scene::IMeshSceneNode* and simply called scene::ISceneNode::setMaterialFlag() rather than scene::IMeshSceneNode::getMesh() first. This was the better way to do it in the first place, rather than taking that extra step that seemed to break it. Finished code:

Code: Select all

if (receiver->rightMouseButtonPressed())
{
    scene::ISceneNode* pointedNode = smgr->getSceneCollisionManager()->getSceneNodeFromCameraBB(camera, -1);
 
    if (selected != 0)
        selected->setMaterialFlag(video::E_MATERIAL_FLAG::EMF_WIREFRAME, false);
 
    selected = pointedNode;
    if (selected != 0)
        selected->setMaterialFlag(video::E_MATERIAL_FLAG::EMF_WIREFRAME, true);
}
Thanks!

-Will
cat.exe
Posts: 34
Joined: Sat Sep 14, 2013 11:52 pm

Re: getSceneNodeFromCameraBB() not behaving as expected

Post by cat.exe »

CuteAlien wrote:Irrlicht doesn't add a skybox. If you created your scene with an editor like irrEdit... I have no idea (never used it). But just take a look at the variable in the debugger after it crashed - then you will know within seconds what type of node that really is. That's why we have debuggers :-)
In reply to this:

No, I do not use a scene editor (and I am now absolutely sure my program is 100% skybox free :) )

I looked at the debugger type and it simply said ISceneNode (which is the pointer type, but it still could be a subclass such as IMeshSceneNode).

Thanks!
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: [Solved] getSceneNodeFromCameraBB() not behaving as expe

Post by CuteAlien »

The debugger usually knows the real type of objects and shows that (even after casting). But then again you usually never have just an ISceneNode - confusing. When you are lucky (and compiling in debug) the base-class (IReferenceCounted) might have set the debug name set which you can check with getDebugName ().
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