I've got a problem with returning this const pointer. Using the debugger showed me that the scene is correctly imported and stored in variable scene. After returning scene, the content pointed by scene is lost and cannot be accessed by the class calling loadData().
const aiScene* IOHandler::loadData(const std::string& pFile){
Assimp::Importer importer;
const aiScene* scene = importer.ReadFile(pFile,
aiProcess_CalcTangentSpace |
aiProcess_Triangulate |
aiProcess_JoinIdenticalVertices |
aiProcess_SortByPType);
return scene;
}
(Importer
and aiScene(struct)
are part of the assimp library and cannot be modified)
I assume that the scene is stored on the stack, the return call resets the stackpointer and the content is lost. How to handle such a problem in c++?
You forgot to read the documentation.
The scene is owned by the Importer
, so it will be destroyed when that goes out of scope. Return importer.GetOrphanedScene()
to take ownership, and remember to delete it when you've finished with it.
Alternatively, you could store the importer somewhere more permanent; but that might not work too well if you need to import and use many scenes at the same time.