我在用assimp和C++进行摆弄,并且编写了一个简单的函数来从文件中加载一个场景。但是,当我尝试返回指针时,该对象会变得混乱,如果我尝试检索成员数据,则会出现访问冲突。这段代码应该证明这种情况:返回一个指针弄乱对象(访问冲突)
const aiScene* ResManager::loadScene(const std::string& pFile)
{
Assimp::Importer importer;
const aiScene* scene = importer.ReadFile(pFile, aiProcessPreset_TargetRealtime_MaxQuality);
if(!scene)
{
printf("%s\n", importer.GetErrorString());
return 0;
}
// If I break the debug here, 'scene' is valid
return scene;
}
void ResManager::loadFromFile(const std::string& pFile)
{
const aiScene* scn = loadScene(pFile);
// If I break the debug here, 'scn' contains gibberish
}
我想我已经错过了一些关于指针和常量等基本要素。有任何想法吗?
这个对象是由进口商持有场景的任何部分?因为这超出了范围。 – nvoigt
在进口商遭到破坏时可能会发生某些事情。 – defube