From bdade023087f5a9323335d9cfba2d40ea14d1fec Mon Sep 17 00:00:00 2001
From: Joseph Mirabel <jmirabel@laas.fr>
Date: Wed, 11 Sep 2019 20:20:30 +0200
Subject: [PATCH] Workaround Assimp bug related to undefined symbols.

---
 include/hpp/fcl/mesh_loader/assimp.h |  6 +++++-
 src/mesh_loader/assimp.cpp           | 26 +++++++++++++-------------
 2 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/include/hpp/fcl/mesh_loader/assimp.h b/include/hpp/fcl/mesh_loader/assimp.h
index 758a3b8a..79ba1808 100644
--- a/include/hpp/fcl/mesh_loader/assimp.h
+++ b/include/hpp/fcl/mesh_loader/assimp.h
@@ -41,6 +41,9 @@
 #include <hpp/fcl/BVH/BVH_model.h>
 
 class aiScene;
+namespace Assimp {
+  class Importer;
+}
 
 namespace hpp
 {
@@ -62,7 +65,8 @@ struct Loader {
 
   void load (const std::string& resource_path);
 
-  aiScene* scene;
+  Assimp::Importer* importer;
+  aiScene const* scene;
 };
 
 /**
diff --git a/src/mesh_loader/assimp.cpp b/src/mesh_loader/assimp.cpp
index 26d157d8..d529ec6d 100644
--- a/src/mesh_loader/assimp.cpp
+++ b/src/mesh_loader/assimp.cpp
@@ -58,18 +58,10 @@ namespace fcl
 namespace internal
 {
 
-Loader::Loader () : scene (NULL) {}
-
-Loader::~Loader ()
+Loader::Loader () : importer (new Assimp::Importer())
 {
- if (scene) delete scene;
-}
-
-void Loader::load (const std::string & resource_path)
-{
-  Assimp::Importer importer;
   // set list of ignored parameters (parameters used for rendering)
-  importer.SetPropertyInteger(AI_CONFIG_PP_RVC_FLAGS,
+  importer->SetPropertyInteger(AI_CONFIG_PP_RVC_FLAGS,
       aiComponent_TANGENTS_AND_BITANGENTS|
       aiComponent_COLORS |
       aiComponent_BONEWEIGHTS |
@@ -82,7 +74,16 @@ void Loader::load (const std::string & resource_path)
       aiComponent_NORMALS
       );
 
-  importer.ReadFile(resource_path.c_str(),
+}
+
+Loader::~Loader ()
+{
+ if (importer) delete importer;
+}
+
+void Loader::load (const std::string & resource_path)
+{
+  scene = importer->ReadFile(resource_path.c_str(),
       aiProcess_SortByPType |
       aiProcess_Triangulate |
       aiProcess_RemoveComponent |
@@ -94,11 +95,10 @@ void Loader::load (const std::string & resource_path)
       aiProcess_JoinIdenticalVertices
       );
 
-  scene = importer.GetOrphanedScene();
   if (!scene)
   {
     const std::string exception_message (std::string ("Could not load resource ") + resource_path + std::string("\n") +
-                                         importer.GetErrorString () + std::string("\n") +
+                                         importer->GetErrorString () + std::string("\n") +
                                          "Hint: the mesh directory may be wrong.");
     throw std::invalid_argument(exception_message);
   }
-- 
GitLab