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()); packfileDate->removeReference();
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?