mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
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:
parent
bf846cd461
commit
8ba6a0d844
@ -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);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user