addReference doesnt work

addReference doesnt work


Im loading a RigidBody out of a binary .hkx file. After loading the RigidBody I want to have the hkPackfileData deleted and therefore I call packfileData->removeReference() to free the memory but it crashes after that, because the RigidBody seems to get deleted aswell. I checked the ReferenceCount of RigidBody and it is indeed zero. I tried to increase the referencecount of my RigidBody with addReference() but it does not work. Here is how I load the RigidBody:

	//Binres laden	
	hkPackfileData* packfileData;
	hkRootLevelContainer* container;
	hkpPhysicsData* mPhysicsData;

	//RigidBody aus der Datei lesen
	packfileData = static_cast(hkSerializeUtil::load(havokFileName.c_str()));
	container = packfileData->getContents();
	mPhysicsData = static_cast(container->findObjectByType(hkpPhysicsDataClass.getName()));
	hkpRigidBody * rb =	mPhysicsData->findRigidBodyByName(havokBodyName.c_str());

Im a little uncertain what I should do now. Is there a way to add a reference to the RigidBody so it doesnt get destroyed with the packfile? How is this usually handled?


5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
chucky-x's picture

I am not sure, but I think content will not explicitly be copied when loading a hkx file.
So when you add a rigid body from a hkx to your world,
you add a pointer. The pointer is pointing to the loaded hkx memory place,
when removing the hkx content, the rigid body will also be removed.

I am also not removing the reference of the loaded hkx, doing this
all content will be removed too. But I am feeling uneasy too.


good to know, that others have the same problem. I pruned my .hkx file now with the prune filter of the content tool but I still would like to have the rigidBody even after removing the reference from the hkPackfileData object.

I hope this is possible somehow...

sean.thurston's picture

Hi guys,

Keeping the hkPackfileData around is definitely the way to go. The other option is go through and copy out all your rigid body information into new rigid bodies. I don't really see a reason for doing that. There have been a couple of threads kind of related to this: (kind of towards the middle of the page)

We keep the hkPackfileData around in our demos as well. Basically when you clean up the hkPackfileData, it calls the destructor on all the objects that it owns.

in terms of pruning things out of the packfile, that is fine, but it is not necessarily related to this problem. When it gets down towards the end of your project you are probably going to want to prune as much information as you can from the hkPackfile. You can check out the Havok Content Tools->Common Concepts->Animation:Controlling File Size in the docs. It has information on the stuff that can be safely pruned.

I hope that helps.


Developer Support Engineer Havok

ok, thank you for the answer sean.thurston. I have to change some things now in my program, but that is ok with me ;)

Login to leave a comment.