assimp: don't reuse Importer object when loading multiple models

This works around a crash in v4.1.0 when loading multiple .ply files in sequence.  (I have not reproduced the crash with the latest Assimp master.)
This commit is contained in:
rdb 2019-02-19 21:23:37 +01:00
parent bf846cd461
commit 8ba6a0d844

View File

@ -15,6 +15,8 @@
#include "config_assimp.h" #include "config_assimp.h"
#include "assimpLoader.h" #include "assimpLoader.h"
#include <assimp/cimport.h>
using std::string; using std::string;
TypeHandle LoaderFileTypeAssimp::_type_handle; TypeHandle LoaderFileTypeAssimp::_type_handle;
@ -23,7 +25,7 @@ TypeHandle LoaderFileTypeAssimp::_type_handle;
* *
*/ */
LoaderFileTypeAssimp:: LoaderFileTypeAssimp::
LoaderFileTypeAssimp() : _loader(new AssimpLoader) { LoaderFileTypeAssimp() : _loader(nullptr) {
} }
/** /**
@ -31,9 +33,6 @@ LoaderFileTypeAssimp() : _loader(new AssimpLoader) {
*/ */
LoaderFileTypeAssimp:: LoaderFileTypeAssimp::
~LoaderFileTypeAssimp() { ~LoaderFileTypeAssimp() {
if (_loader != nullptr) {
delete _loader;
}
} }
/** /**
@ -58,9 +57,22 @@ get_extension() const {
*/ */
string LoaderFileTypeAssimp:: string LoaderFileTypeAssimp::
get_additional_extensions() const { get_additional_extensions() const {
string exts; aiString aexts;
_loader->get_extensions(exts); aiGetExtensionList(&aexts);
return exts;
// The format is like: *.mdc;*.mdl;*.mesh.xml;*.mot
std::string ext;
char *sub = strtok(aexts.data, ";");
while (sub != nullptr) {
ext += sub + 2;
sub = strtok(nullptr, ";");
if (sub != nullptr) {
ext += ' ';
}
}
return ext;
} }
/** /**
@ -82,10 +94,13 @@ load_file(const Filename &path, const LoaderOptions &options,
assimp_cat.info() assimp_cat.info()
<< "Reading " << path << "\n"; << "Reading " << path << "\n";
if (!_loader->read(path)) { AssimpLoader loader;
loader.local_object();
if (!loader.read(path)) {
return nullptr; return nullptr;
} }
_loader->build_graph(); loader.build_graph();
return DCAST(PandaNode, _loader->_root); return DCAST(PandaNode, loader._root);
} }