adding collision listeners on havok load

adding collision listeners on havok load

hi,

I have an hkx file which i'd like to put a fracture listener on some rigid body. I have some code but it's been getting some errors on the addEntity Method below is a sample code.

markForWrite();
...

		// Add all the physics systems to the world
		for ( int i = 0; i < physicsData->getPhysicsSystems().getSize(); ++i )
		{
			physicsWorld->addPhysicsSystem( physicsData->getPhysicsSystems()[i] );
		}
		//Try and add collisionListener
		hkArray  psArray;
		physicsWorld->getWorldAsSystems(psArray);
		
			for(int i=0; igetRigidBodies()[j];
					
					hkArray m_fracturedBodies;
					GlassFractureListener *gf = new GlassFractureListener(&m_fracturedBodies,0.5f);
					rb->addCollisionListener(gf);
					
					gf->addReference();
					physicsWorld->addEntity(rb);
					rb->addReference();
					
					physicsWorld->addReference();

				}
			}
...
unmarkForWrite();

I've got a stack trace below for this one:

Stack was:

testy.exe!hkpWorld::addEntity(hkpEntity * entity=0x05042530, hkpEntityActivation initialActivationState=HK_ENTITY_ACTIVATION_DO_ACTIVATE) Line 724 + 0x68 bytes C++
testy.exe!HavokPhysics::initHavok() Line 215 C++
testy.exe!OgreFrameListener::OgreFrameListener(Ogre::RenderWindow * win=0x0159fd20, Ogre::Camera * cam=0x015f5a98, Ogre::SceneManager * sceneMgr=0x015ebfa8) Line 30 C++
testy.exe!TutorialApplication::createFrameListener() Line 195 + 0x43 bytes C++
testy.exe!ExampleApplication::setup() Line 140 + 0xf bytes C++
testy.exe!ExampleApplication::go() Line 89 + 0xf bytes C++
testy.exe!WinMain(HINSTANCE__ * hInst=0x00400000, HINSTANCE__ * __formal=0x00000000, char * strCmdLine=0x00161f01, HINSTANCE__ * __formal=0x00000000) Line 221 + 0x8 bytes C++
testy.exe!__tmainCRTStartup() Line 574 + 0x35 bytes C
testy.exe!WinMainCRTStartup() Line 399 C

Would this be the proper way of loading the fracture listener?

thanks.

8 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hi gonx,

Is this a crash or an assert? If it is an assert, can you give me the assert number?

That being said, I would say that you don't want to instantiate the collision listener inside your loop. It is best to declare it outside the loop and one time. Then just attach that to each rigid body. Give that a try and see if you get some better results.

I still think it might be best to just keep the packfile/packfile reader around instead of using addReference on every rigid body/phantom/whatever you get from the packfile. Might save you a little hassle.

Thanks,
Sean

Developer Support Engineer Havok www.havok.com

Quoting - sean.thurston

Hi gonx,

Is this a crash or an assert? If it is an assert, can you give me the assert number?

That being said, I would say that you don't want to instantiate the collision listener inside your loop. It is best to declare it outside the loop and one time. Then just attach that to each rigid body. Give that a try and see if you get some better results.

I still think it might be best to just keep the packfile/packfile reader around instead of using addReference on every rigid body/phantom/whatever you get from the packfile. Might save you a little hassle.

Thanks,
Sean

Hi sean,

I'm not sure how you mean by whether it's a crash or assert. =) but i see no assert number on the stack trace i posted but on debug mode. I'm a complete noob on debugging. But i notice that it just seems to break on line 21.

About using packfile reader instead of addReference, i'm still new to the packfilereader so i'll be reading on this one as well.

I'll be trying your suggestions and hope it goes well.

Thanks.

Hi again sean,

I tried this one again using a different way. I'm now getting some access violations this time. Could this be related on how i was setting up the listeners earlier?

hkpRigidBody *tempbody1 = havok->getPhysicsData()->findRigidBodyByName("pCube1");

Stack trace was:

testy.exe!hkVector4::operator=(const hkVector4 & v={...}) Line 96 + 0x6 bytes C++
testy.exe!hkVector4::hkVector4(const hkVector4 & v={...}) Line 118 C++
testy.exe!OgreFrameListener::OgreFrameListener(Ogre::RenderWindow * win=0x0159fd20, Ogre::Camera * cam=0x015f5a98, Ogre::SceneManager * sceneMgr=0x015ebfa8) Line 52 C++
testy.exe!TutorialApplication::createFrameListener() Line 195 + 0x43 bytes C++
testy.exe!ExampleApplication::setup() Line 140 + 0xf bytes C++
testy.exe!ExampleApplication::go() Line 89 + 0xf bytes C++
testy.exe!WinMain(HINSTANCE__ * hInst=0x00400000, HINSTANCE__ * __formal=0x00000000, char * strCmdLine=0x00161f01, HINSTANCE__ * __formal=0x00000000) Line 221 + 0x8 bytes C++
testy.exe!__tmainCRTStartup() Line 574 + 0x35 bytes C
testy.exe!WinMainCRTStartup() Line 399 C

On line 96 the variable x was -1.0737418e+008 according to the debugger.

inline void hkVector4::operator= (const hkVector4& v)
{
x = v.x; <-- error was here.
y = v.y;
z = v.z;
w = v.w;
}

Thanks.

Hi gonx,

It looks like there is a Vector4 that is not being initialized. The callstack looks like it is coming directly from the Ogre portion of your code. Do you set up some vectors before or after you call the line of code that you have listed above?

As for asserts vs crashes, asserts are checks that we have put into the code to give debugging information. They are only turned on in debug mode. You should be able to check the Output to see if you hit an assert or not.

Hopefully that helps,

Sean

Developer Support Engineer Havok www.havok.com

Quoting - sean.thurston

Hi gonx,

It looks like there is a Vector4 that is not being initialized. The callstack looks like it is coming directly from the Ogre portion of your code. Do you set up some vectors before or after you call the line of code that you have listed above?

As for asserts vs crashes, asserts are checks that we have put into the code to give debugging information. They are only turned on in debug mode. You should be able to check the Output to see if you hit an assert or not.

Hopefully that helps,

Sean

hi sean,

I finally found the problem. My application couldn't load the physics system via getWorld()->getWorldAsSystems(...); and parse the rigid bodies that were in it after i supposedly added each rigidbody with a collision listener.

I was wondering if this is a correct way of adding the fracture listener like the one UseCase->Fracture->SimpleFracturePatternsDemo

Currently what i did unfortunately didnt work. On loading havok

- load the .hkx file onto a physicsData variable

- added Physics system to some physicsWorld variable via

for ( int i = 0; i < physicsData->getPhysicsSystems().getSize(); ++i )
{
physicsWorld->addPhysicsSystem( physicsData->getPhysicsSystems()[i] );
}

- tried adding a collision listener( like the one in fracture demo)

physicsWorld->getWorldAsSystems(...)

for each rigid body {

rigidbody->addCollisionListener(someFractureListener);

physicsWorld->addEntity(rigidbody)

}

The fracture demo unlike my case makes its own hkpWorld. I load my hkpWorld from an hkx file. Would the proper way to add the listener is through this?

Thanks.

Hi gonx,

I understand what is going on now. Here is what i think you need to do:

1) Create the world. Hopefully physicsWorld is already created before the above code block.

2) Add all the physics systems to the world. This will include all the rigid bodies.

3) Add the collision listener to whichever bodies you want to have it. Do not add that rigid body back to the world. They should already be in the world. It will get added to the world when you added all the physics systems to the world. This probably threw an assert.

Hopefully that will do it. You only need too add each rigid body once to the world.

Thanks,
Sean

Developer Support Engineer Havok www.havok.com

Quoting - sean.thurston

Hi gonx,

I understand what is going on now. Here is what i think you need to do:

1) Create the world. Hopefully physicsWorld is already created before the above code block.

2) Add all the physics systems to the world. This will include all the rigid bodies.

3) Add the collision listener to whichever bodies you want to have it. Do not add that rigid body back to the world. They should already be in the world. It will get added to the world when you added all the physics systems to the world. This probably threw an assert.

Hopefully that will do it. You only need too add each rigid body once to the world.

Thanks,
Sean

Hi sean,

Thanks! it's ok now.

Login to leave a comment.