我在使用 Apple LLVM 3.0 编译器时遇到了一个非常奇怪的崩溃。 所以有一些代码,使用 Assimp加载 Assets 并创建场景(我已经排除了所有代码,即使这样它也会崩溃):
aiScene* ai_scene = const_cast<aiScene*>(aiImportFileFromMemory(fileBuf, fInfo.uncompressed_size, aiProcessPreset_TargetRealtime_MaxQuality, NULL));
delete ai_scene;
这是 GCC 堆栈跟踪的屏幕截图:
这里是 LLVM:
在 LLVM 版本中,析构函数被调用了两次(这可能就是我崩溃的原因)。
我还应该提到,所有析构函数代码都位于头文件中,并且仅在设备上崩溃(在 iPod 4 和 iPad 2 上测试过)。
这是 LLVM 编译器中的错误(可能是在生成 arm 程序集时)还是我遗漏了什么?
编辑:
如果有人遇到类似问题,请使用 aiReleaseImport(scene)
而不是 delete scene;
最佳答案
你根本不应该删除
那个指针。阅读文档。它明确指出您不应尝试以任何方式释放它。
If the call succeeds, the contents of the file are returned as a pointer to an aiScene object. The returned data is intended to be read-only, the importer keeps ownership of the data and will destroy it upon destruction. If the import fails, NULL is returned. A human-readable error description can be retrieved by calling aiGetErrorString().
此外,文档明确指出它是只读的,所以不要 const_cast
const
。
关于iphone - 应用程序在 Apple LLVM 3.0 上崩溃但在 LLVM GCC 4.2 上运行正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7968286/