Page 1 of 1

[irrBullet] Runtime crash when using IAttributes

Posted: Mon Oct 20, 2014 9:46 am
by RTCgee
I have the following code to process irrBullet collisions executed 60 times per second:

Code: Select all

void processCollisions(){
    for(unsigned int i=0; i < world->getNumManifolds(); i++){
        ICollisionCallbackInformation *info = world->getCollisionCallback(i);
        unsigned int numContacts = info->getPointer()->getNumContacts();
        for(unsigned int j=0; j < numContacts; j++)
        if(info->getContactPoint(j).getDistance()<1.5f && info->getContactPoint(j).getLifeTime() < 2.0f){
            io::IAttributes* body0 = info->getBody0()->getAttributes();
            io::IAttributes* body1 = info->getBody1()->getAttributes();
            core::stringc type0 = body0->existsAttribute("Type")? body0->getAttributeAsString("Type") :L"None",
                          type1 = body1->existsAttribute("Type")? body1->getAttributeAsString("Type") :L"None";
            /* Look at the types and call functions that fit */ }
        info->getPointer()->clearManifold();}}
World is my irrBullet world, the Type attribute, obviously, holds the type of the body.
The moment there is a collision, a runtime crash occurs.
With debugging I have found that this happens the moment body0->existsAttribute("Type") is called, but some more debugging showed that any function call on body0 and body1 result in a crash.
Although this is typical for a null-pointer, the pointers aren't 0x000000 and will be true when used as a bool.
I've already tried recompiling irrlicht and irrBullet without success.

Re: [irrBullet] Runtime crash when using IAttributes

Posted: Mon Oct 20, 2014 12:03 pm
by CuteAlien
Maybe your getBody functions return uninitialized pointers?

Re: [irrBullet] Runtime crash when using IAttributes

Posted: Mon Oct 20, 2014 12:29 pm
by RTCgee
CuteAlien wrote:Maybe your getBody functions return uninitialized pointers?
That would be a bug in irrBullet and I assume that when there is a collision there are 2 objects involved.
But an uninitialized pointer would explain why it acts like a nullpointer.

Re: [irrBullet] Runtime crash when using IAttributes

Posted: Mon Oct 20, 2014 12:34 pm
by RTCgee
I might have found the problem by looking at what the getBody function actually does, apperantly it uses the "userpointer" of the bullet body, but I used it myself too and have probably set it to a different value.
I'll see if it works after having changed the function.

Re: [irrBullet] Runtime crash when using IAttributes

Posted: Mon Oct 20, 2014 12:41 pm
by RTCgee
Seems to work now.
As a note to irrBullet users:
don't try to change the userPointer of a bullet body, irrBullet will set it to a SCollisionObjectIdentification pointer with information about the ICollisionObject automatically.