Crash when cloning hkaRagdollInstance

Crash when cloning hkaRagdollInstance

I use the following code to get a hkaRagdollInstance pointer:

hkRootLevelContainer* container=  static_cast<hkRootLevelContainer*>(hkNativePackfileUtils::loadInPlace(data,szData));

hkaRagdollInstance *corereinterpret_cast<hkaRagdollInstance*>( container->findObjectByType( hkaRagdollInstanceClass.getName() ));

hkaRagdollInstance *p=core->clone();//crashes here!! 

(data/szData contains a hkx file's raw data,which in binary package format.)

Both the core and container pointer are valid,and their contents seem correct.and I can access them without crashing.

But when I call the clone function,it crashes. Also the following codes will lead a crash too:

const hkArray<hkpConstraintInstance*>& constraints =core->getConstraintArray();
hkpInertiaTensorComputer::optimizeInertiasOfConstraintTree( constraints.begin(), constraints.getSize(),core->getRigidBodyOfBone(0) );

So I switch to another method to load the file,I dump a xml/tag hkx file  and using the following codes to read it

hkSerializeUtil::ErrorDetails ed;
hkResource *res=hkSerializeUtil::load(,data.szData,&ed);

To my surprise, it fails and reports the following error:

+ m_stringAndFlag 0x07bb5cb1 "nable to version data of class hkpSetupStabilizationAtom, version 0x00000001
Patching to latest version failed. Have you registered the necessary patches? e.g. hkFeature_serializeRegisterKeycodePatches() See the hkError output for more details

Seems that I am loading from an old format file.But the version of the content tool and sdk are both 2011.3.1,do this 2 version acturally match?

The attachment are the files(binary and tag) I am loading.

Can some one see this problem for me? Thanks.

下载 1.zip64.22 KB
2 帖子 / 0 全新

Hey ixnehc,

Can you give me the CallStack of your different crashes? Also can you try loading binary.hkx using the NativePackfileLoadDemo and let me know if it works?
Your code should look like:

hkRootLevelContainer* container = hkSerializeUtil::loadObject("Resources/Common/Api/Serialize/Test/binary.hkx") )


		hkPackfileWriter::Options options;

		hkSerializeUtil::savePackfile( container, hkRootLevelContainerClass, hkOstream(inputBuffer).getStreamWriter(), options );

		delete container;


	HK_ASSERT2(0x26f2503c, inputBuffer.getSize(), "file load failed");

        // Now we have native packfile data in the 'm_packfileBuf' variable.

	// Extract only valuable data, stripping out all extras, such as headers and fixups tables

	// and load it into m_dataBuffer
	// Load the buffer and get the top level object in the file in one step

	hkRootLevelContainer* container = HK_NULL;

	hkSerializeUtil::ErrorDetails ed;
	// Load the buffer in-place. We swap the contents into m_dataBuffer rather than allocating a new data buffer.



		container = static_cast(hkNativePackfileUtils::loadInPlace(m_dataBuffer.begin(), m_dataBuffer.getSize()));

		hkaRagdollInstance *core = reinterpret_cast( container->findObjectByType( hkaRagdollInstanceClass.getName() ));

		hkaRagdollInstance *p = core->clone();//crashes here!! 
		const hkArray& constraints = core->getConstraintArray();

		hkpInertiaTensorComputer::optimizeInertiasOfConstraintTree( constraints.begin(), constraints.getSize(),core->getRigidBodyOfBone(0) ); //other crash here!!

Finally, can you tell me if when running the following code:
hkClassNameRegistry* classReg = hkBuiltinTypeRegistry::getInstance().getClassNameRegistry();
const hkClass* k = classReg->getClassByName("hkpSetupStabilizationAtom");
bool isVersion1 = (k->getDescribedVersion() == 1);

isVersion1 is true? If not can you tell me what k->getDescribedVersion() is equal to? You will need to #include for the above code to run.

Thanks for letting me know,


David G.
Developer Support Engineer