From 288a638a835ce3727d6c1c939b461e2956b5284d Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Wed, 22 Jan 2020 12:19:05 +0200 Subject: [PATCH 1/4] X: Only create animation key arrays if there are some keys --- code/X/XFileImporter.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/code/X/XFileImporter.cpp b/code/X/XFileImporter.cpp index 122033b08..ff4ee1378 100644 --- a/code/X/XFileImporter.cpp +++ b/code/X/XFileImporter.cpp @@ -513,6 +513,7 @@ void XFileImporter::CreateAnimations( aiScene* pScene, const XFile::Scene* pData } else { // separate key sequences for position, rotation, scaling nbone->mNumPositionKeys = (unsigned int)bone->mPosKeys.size(); + if (nbone->mNumPositionKeys != 0) { nbone->mPositionKeys = new aiVectorKey[nbone->mNumPositionKeys]; for( unsigned int c = 0; c < nbone->mNumPositionKeys; ++c ) { aiVector3D pos = bone->mPosKeys[c].mValue; @@ -520,9 +521,11 @@ void XFileImporter::CreateAnimations( aiScene* pScene, const XFile::Scene* pData nbone->mPositionKeys[c].mTime = bone->mPosKeys[c].mTime; nbone->mPositionKeys[c].mValue = pos; } + } // rotation nbone->mNumRotationKeys = (unsigned int)bone->mRotKeys.size(); + if (nbone->mNumRotationKeys != 0) { nbone->mRotationKeys = new aiQuatKey[nbone->mNumRotationKeys]; for( unsigned int c = 0; c < nbone->mNumRotationKeys; ++c ) { aiMatrix3x3 rotmat = bone->mRotKeys[c].mValue.GetMatrix(); @@ -531,12 +534,15 @@ void XFileImporter::CreateAnimations( aiScene* pScene, const XFile::Scene* pData nbone->mRotationKeys[c].mValue = aiQuaternion( rotmat); nbone->mRotationKeys[c].mValue.w *= -1.0f; // needs quat inversion } + } // scaling nbone->mNumScalingKeys = (unsigned int)bone->mScaleKeys.size(); + if (nbone->mNumScalingKeys != 0) { nbone->mScalingKeys = new aiVectorKey[nbone->mNumScalingKeys]; for( unsigned int c = 0; c < nbone->mNumScalingKeys; c++) nbone->mScalingKeys[c] = bone->mScaleKeys[c]; + } // longest lasting key sequence determines duration if( bone->mPosKeys.size() > 0) From aee292e367658c5410d0a61a6ec1a4825c93eff6 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Wed, 22 Jan 2020 12:20:34 +0200 Subject: [PATCH 2/4] Whitespace --- code/X/XFileImporter.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/code/X/XFileImporter.cpp b/code/X/XFileImporter.cpp index ff4ee1378..70c6869b3 100644 --- a/code/X/XFileImporter.cpp +++ b/code/X/XFileImporter.cpp @@ -514,34 +514,34 @@ void XFileImporter::CreateAnimations( aiScene* pScene, const XFile::Scene* pData // separate key sequences for position, rotation, scaling nbone->mNumPositionKeys = (unsigned int)bone->mPosKeys.size(); if (nbone->mNumPositionKeys != 0) { - nbone->mPositionKeys = new aiVectorKey[nbone->mNumPositionKeys]; - for( unsigned int c = 0; c < nbone->mNumPositionKeys; ++c ) { - aiVector3D pos = bone->mPosKeys[c].mValue; + nbone->mPositionKeys = new aiVectorKey[nbone->mNumPositionKeys]; + for( unsigned int c = 0; c < nbone->mNumPositionKeys; ++c ) { + aiVector3D pos = bone->mPosKeys[c].mValue; - nbone->mPositionKeys[c].mTime = bone->mPosKeys[c].mTime; - nbone->mPositionKeys[c].mValue = pos; - } + nbone->mPositionKeys[c].mTime = bone->mPosKeys[c].mTime; + nbone->mPositionKeys[c].mValue = pos; + } } // rotation nbone->mNumRotationKeys = (unsigned int)bone->mRotKeys.size(); if (nbone->mNumRotationKeys != 0) { - nbone->mRotationKeys = new aiQuatKey[nbone->mNumRotationKeys]; - for( unsigned int c = 0; c < nbone->mNumRotationKeys; ++c ) { - aiMatrix3x3 rotmat = bone->mRotKeys[c].mValue.GetMatrix(); + nbone->mRotationKeys = new aiQuatKey[nbone->mNumRotationKeys]; + for( unsigned int c = 0; c < nbone->mNumRotationKeys; ++c ) { + aiMatrix3x3 rotmat = bone->mRotKeys[c].mValue.GetMatrix(); - nbone->mRotationKeys[c].mTime = bone->mRotKeys[c].mTime; - nbone->mRotationKeys[c].mValue = aiQuaternion( rotmat); - nbone->mRotationKeys[c].mValue.w *= -1.0f; // needs quat inversion - } + nbone->mRotationKeys[c].mTime = bone->mRotKeys[c].mTime; + nbone->mRotationKeys[c].mValue = aiQuaternion( rotmat); + nbone->mRotationKeys[c].mValue.w *= -1.0f; // needs quat inversion + } } // scaling nbone->mNumScalingKeys = (unsigned int)bone->mScaleKeys.size(); if (nbone->mNumScalingKeys != 0) { - nbone->mScalingKeys = new aiVectorKey[nbone->mNumScalingKeys]; - for( unsigned int c = 0; c < nbone->mNumScalingKeys; c++) - nbone->mScalingKeys[c] = bone->mScaleKeys[c]; + nbone->mScalingKeys = new aiVectorKey[nbone->mNumScalingKeys]; + for( unsigned int c = 0; c < nbone->mNumScalingKeys; c++) + nbone->mScalingKeys[c] = bone->mScaleKeys[c]; } // longest lasting key sequence determines duration From 1edb52c0de4006f7f0383670ef12aacedfd4edeb Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Wed, 22 Jan 2020 12:20:49 +0200 Subject: [PATCH 3/4] ScenePreprocessor: Assert some properties about animation channels --- code/Common/ScenePreprocessor.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/code/Common/ScenePreprocessor.cpp b/code/Common/ScenePreprocessor.cpp index 432a3d766..a47053de4 100644 --- a/code/Common/ScenePreprocessor.cpp +++ b/code/Common/ScenePreprocessor.cpp @@ -217,6 +217,7 @@ void ScenePreprocessor::ProcessAnimation (aiAnimation* anim) // No rotation keys? Generate a dummy track if (!channel->mNumRotationKeys) { + ai_assert(!channel->mRotationKeys); channel->mNumRotationKeys = 1; channel->mRotationKeys = new aiQuatKey[1]; aiQuatKey& q = channel->mRotationKeys[0]; @@ -225,10 +226,13 @@ void ScenePreprocessor::ProcessAnimation (aiAnimation* anim) q.mValue = rotation; ASSIMP_LOG_DEBUG("ScenePreprocessor: Dummy rotation track has been generated"); + } else { + ai_assert(channel->mRotationKeys); } // No scaling keys? Generate a dummy track if (!channel->mNumScalingKeys) { + ai_assert(!channel->mScalingKeys); channel->mNumScalingKeys = 1; channel->mScalingKeys = new aiVectorKey[1]; aiVectorKey& q = channel->mScalingKeys[0]; @@ -237,10 +241,13 @@ void ScenePreprocessor::ProcessAnimation (aiAnimation* anim) q.mValue = scaling; ASSIMP_LOG_DEBUG("ScenePreprocessor: Dummy scaling track has been generated"); + } else { + ai_assert(channel->mScalingKeys); } // No position keys? Generate a dummy track if (!channel->mNumPositionKeys) { + ai_assert(!channel->mPositionKeys); channel->mNumPositionKeys = 1; channel->mPositionKeys = new aiVectorKey[1]; aiVectorKey& q = channel->mPositionKeys[0]; @@ -249,6 +256,8 @@ void ScenePreprocessor::ProcessAnimation (aiAnimation* anim) q.mValue = position; ASSIMP_LOG_DEBUG("ScenePreprocessor: Dummy position track has been generated"); + } else { + ai_assert(channel->mPositionKeys); } } } From a74e13d6b27a08f314e701eaca910a3f5e247802 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Wed, 22 Jan 2020 12:22:08 +0200 Subject: [PATCH 4/4] Re-enable dwarf.x import test --- test/unit/utXImporterExporter.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test/unit/utXImporterExporter.cpp b/test/unit/utXImporterExporter.cpp index 15e19cf01..2c6830978 100644 --- a/test/unit/utXImporterExporter.cpp +++ b/test/unit/utXImporterExporter.cpp @@ -132,15 +132,8 @@ TEST(utXImporter, TestFormatDetection) { } -#if 0 // FIXME: disabled because it leaks memory - - TEST(utXImporter, importDwarf) { Assimp::Importer importer; const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_NONBSD_DIR "/X/dwarf.x", aiProcess_ValidateDataStructure); ASSERT_NE(nullptr, scene); } - - -#endif // 0 -