I have const struct aiScene *scene; declared in class.
In the function where I define scene = importer.ReadFile(file, aiProcess_Triangulate); , the scene struct is accessible. I can print out scene->mNumMeshes for example.
Problem is that scene is not correclty accessible from another functions. If I try to print out scene->mNumMeshes then it prints different numbers every time (memory addresses?).
How can I make scene accessible from every function in class?
It’s impossible to be sure without knowing what’s in
importer.ReadFile, but a good guess would be thatimporter.ReadFilereturns a pointer to a structure on the stack. After it returns, the structure will quickly get overwritten by other data — in your first experiment you may just have gotten lucky to get at it before anything else reused that location.Make sure that
ReadFilereturns a heap-allocated structure rather than a local one.