简体   繁体   中英

C++ simple object destruction error

I have written a code which contains a const variable in its class declaration. However I initialize the value of the variable in a function of the class. And I can use that variable without any pain throughout that class. But when I try to access that variable via another function of the class I cannot . It seems its value is set to NULL . Here is the declaration of the class (the variable part only)

public:
    const aiScene *pScene;

And I am initializing it in a function named LoadModel()

pScene = imp.ReadFile(fileName,
    aiProcess_CalcTangentSpace |
    aiProcess_ConvertToLeftHanded |
    aiProcess_Triangulate |
    aiProcess_GenSmoothNormals |
    aiProcess_OptimizeMeshes);

if (pScene == NULL)
    MessageBoxA(NULL, imp.GetErrorString(), "Error", MB_OK);

If I call a function called Update() in this LoadModel() function which uses this variable it works perfectly but when I call it in Render() function of the same class the program crashes. I can see in the debugger that the pScene has some error "Unable to read memory"

Made the variable "imp" global. Silly mistake....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM