Skip to content

Commit

Permalink
Merge pull request #21 from RichardTea/bug-3201-collada_root_meshes
Browse files Browse the repository at this point in the history
Ensure to delete the scene copy after the test
  • Loading branch information
RichardTea authored May 5, 2020
2 parents cdad82e + dc85502 commit 2837446
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions test/unit/utColladaImportExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ using namespace Assimp;

class utColladaImportExport : public AbstractImportExportBase {
public:
// Clones the scene in an exception-safe way
struct SceneCloner {
SceneCloner(const aiScene *scene) {
sceneCopy = nullptr;
SceneCombiner::CopyScene(&sceneCopy, scene);
}

~SceneCloner() {
delete sceneCopy;
sceneCopy = nullptr;
}
aiScene *sceneCopy;
};

virtual bool importerTest() final {
Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/Collada/duck.dae", aiProcess_ValidateDataStructure);
Expand Down Expand Up @@ -231,12 +245,10 @@ TEST_F(utColladaImportExport, exportRootNodeMeshTest) {
ASSERT_EQ(0u, scene->mRootNode->mNumMeshes) << "Collada import should not give the root node a mesh";

{
// Clone the scene and give the root node a mesh and a transform
aiScene *rootMeshScene = nullptr;
SceneCombiner::CopyScene(&rootMeshScene, scene);
ASSERT_TRUE(rootMeshScene != nullptr) << "Fatal: could not copy scene!";
SceneCloner clone(scene);
ASSERT_TRUE(clone.sceneCopy != nullptr) << "Fatal: could not copy scene!";
// Do this by moving the meshes from the first child that has some
aiNode *rootNode = rootMeshScene->mRootNode;
aiNode *rootNode = clone.sceneCopy->mRootNode;
ASSERT_TRUE(rootNode->mNumChildren > 0) << "Fatal: root has no children";
aiNode *meshNode = rootNode->mChildren[0];
ASSERT_EQ(1u, meshNode->mNumMeshes) << "Fatal: First child node has no duck mesh";
Expand All @@ -248,10 +260,12 @@ TEST_F(utColladaImportExport, exportRootNodeMeshTest) {
rootNode->mMeshes[i] = meshNode->mMeshes[i];
}

// Remove the meshes from the original node
meshNode->mNumMeshes = 0;
delete[] meshNode->mMeshes;
meshNode->mMeshes = nullptr;

ASSERT_EQ(AI_SUCCESS, exporter.Export(rootMeshScene, "collada", outFile)) << "Fatal: Could not export file";
ASSERT_EQ(AI_SUCCESS, exporter.Export(clone.sceneCopy, "collada", outFile)) << "Fatal: Could not export file";
}

// Reimport and look for meshes
Expand Down

0 comments on commit 2837446

Please sign in to comment.