[SOLVED] Ray collision fails when pointing to SKYBOX

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
ibax
Posts: 193
Joined: Thu Jun 21, 2007 8:56 am
Location: hungary
Contact:

[SOLVED] Ray collision fails when pointing to SKYBOX

Post by ibax »

Hi,

I made a setup for ray collision detection:

Code: Select all

 
ICameraSceneNode* cam = device->getSceneManager()->getActiveCamera();
ISceneCollisionManager* collMan = smgr->getSceneCollisionManager();
core::line3d<f32> ray;
ray.start = cam->getPosition();
ray.end = ray.start + (cam->getTarget() - ray.start).normalize() * 1000.0f;
core::vector3df intersection;
core::triangle3df hitTriangle;
ISceneNode * selectedSceneNode = collMan->getSceneNodeAndCollisionPointFromRay(ray,intersection,hitTriangle,0,0);
 
When my mouse pointer is over an octree scene node, than it works correctly, but when I'm pointing (no click, just moving the mouse to the skybox) to a SKYBOX, than my application crashes.

Is something special with the SKYBOX? Can I somehow ignore it from the ray collision detection? I tried to ignore its nodeID, but I can only check for the ID or for the NAME only after I pointed to it, so the

Code: Select all

getSceneNodeAndCollisionPointFromRay
part is allways executed... I tried also to put a 3D mesh with invisible material over the whole model, but this also did not worked.

I tried to setup a triangle selector for both OCTREE ans SKYBOX, without success...
Last edited by ibax on Wed Oct 15, 2014 4:19 pm, edited 1 time in total.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Ray collision fails when pointing to SKYBOX

Post by CuteAlien »

As long as you don't add the skybox to a triangleselector it will be ignored. Maybe you handle it wrong when the results returns a null-pointer?
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
ibax
Posts: 193
Joined: Thu Jun 21, 2007 8:56 am
Location: hungary
Contact:

Re: Ray collision fails when pointing to SKYBOX

Post by ibax »

Triangleselector is added to octree and to skybox as well...

Code: Select all

 
if ( node->getType() ==   ESNT_OCTREE  ||  node->getType() == ESNT_SKY_BOX )
    {
        io::IAttributes* attribs = getDevicePointer()->getFileSystem()->createEmptyAttributes();
        if (attribs)
        {
            node->serializeAttributes(attribs);
            core::stringc name = attribs->getAttributeAsString("Mesh");
            attribs->drop();
            scene::IAnimatedMesh* mesh = smgr->getMesh(name.c_str());
            if (mesh)
            {
                selector = smgr->createOctTreeTriangleSelector(mesh->getMesh(0), node, 128);
                node->setTriangleSelector(selector);
                metaSelector->addTriangleSelector(selector);
                selector->drop();
            }
 
        }
 
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Ray collision fails when pointing to SKYBOX

Post by CuteAlien »

That's probably the problem. A skybox has no mesh in the Irrlicht sense - it's just a node doing the drawing itself without a typical mesh. So you can't create triangleselectors for it. But as you don't want to include it anyway just don't add a triangleselector for it.
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
ibax
Posts: 193
Joined: Thu Jun 21, 2007 8:56 am
Location: hungary
Contact:

Re: Ray collision fails when pointing to SKYBOX

Post by ibax »

Hi,

Originally the line looked like this:

Code: Select all

if ( node->getType() ==   ESNT_OCTREE )
The freezing problem was also there. So I tried to find a solution in the irrlicht forum. I saw, that the triangleselector is required when using ray collision detection, so I modified that line to this:

Code: Select all

if ( node->getType() ==   ESNT_OCTREE  ||  node->getType() == ESNT_SKY_BOX )
But the problem still exists...

What is the required/correct behaviour, when a ray collision detection 'detects' an ESNT_SKY_BOX? What should happen?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Ray collision fails when pointing to SKYBOX

Post by CuteAlien »

It's not possible so far. You need triangles for triangle-selectors and you can't get them from a skybox. If it did freeze before you added a triangleselector to the skybox then there is a second problem maybe. I must admit I don't know right now what happens when you add a skybox to a triangleselector, it shouldn't really crash usually. But it can't work - so don't do it.

Then again - I think you like don't add one for the skybox. Because looking at your code you follow it by a smgr->getMesh which is unlikely to work for a skybox (unless you have a mesh with the name of your skybox or something strange like that).

So my guess would be - it crashes more likely in the place where you check collisions. So ... where _does_ it crash? What line does the debugger stop in?
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
ibax
Posts: 193
Joined: Thu Jun 21, 2007 8:56 am
Location: hungary
Contact:

Re: Ray collision fails when pointing to SKYBOX

Post by ibax »

where _does_ it crash? What line does the debugger stop in?
I made a screenshot about the debugger:
Image

So I think, the problem is with the line:

Code: Select all

 
ISceneNode * selectedSceneNode = collMan->getSceneNodeAndCollisionPointFromRay(
                        ray,
                        intersection,   // This will be the position of the collision
                        hitTriangle,    // This will be the triangle hit in the collision
                        0,              // This ensures that only nodes that we have set up to be pickable are considered
                        0);             // Check the entire scene (this is actually the implicit default)
 
Is there a "collision point", when the reached scene node is a SKY_BOX?

I also tried to have "walls" (octree) with transparent material between my camera and the SKY_BOX, I thought it will work, but it this scenario also crashed...
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Ray collision fails when pointing to SKYBOX

Post by CuteAlien »

If you look closely at the text of your exception you'll see that it says: "Access violation reading location 0x00000000".
Access violation means you access memory which your application has not reserved and the address given is the one which your program tries to access. 0x00000000 is a null pointer - which is typically a result returned when nothing is found. It's also the value to which you should initialize all pointers always. In this case it returns 0 when no collision is found.

But you have to check for it before doing anything with a pointer. A call like selectedSceneNode->something will always crash if selectedSceneNode is 0. So check for it first. if ( selectedSceneNode == 0) then do some stuff without that pointer - in this case nothing as there was no collision.

Generally a good idea - before you use any pointer always check first if it's not 0 (or NULL or with c++11 you can check for nullptr). If you browse a little bit through the Irrlicht sources (or really any typical c++ sources) you will see such checks all the time.
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
ibax
Posts: 193
Joined: Thu Jun 21, 2007 8:56 am
Location: hungary
Contact:

Re: Ray collision fails when pointing to SKYBOX

Post by ibax »

SOLVED!

Thanks CuteAlien, that was the trick!!!! :)
Post Reply