Skip to content

Commit

Permalink
Ensure to delete the scene copy after the test
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardTea committed May 5, 2020
1 parent 56a4e61 commit dc85502
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 dc85502

Please sign in to comment.