iphone - 应用程序在 Apple LLVM 3.0 上崩溃但在 LLVM GCC 4.2 上运行正常

标签 iphone c++ gcc llvm

我在使用 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 堆栈跟踪的屏幕截图:

enter image description here

这里是 LLVM:

enter image description here

在 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/

相关文章:

c++ - 证书友好名称

c - gcc -fno-stack-protector 选项

iphone - NSPredicate 在数组中排除 "name"

iphone - 将复选标记放在 UITableViewCell 的左侧

python - 使用和不使用 `-builtin` 交互 SWIG 模块

c++ - 为什么 C++ 编译器会在这里生成一个临时文件?

c - 使用 ncurses 在 C 中打印 Unicode 字符

xcode - 为什么 xcode 5 没有为 newrelic 找到足够的头文件,尽管库在那里?

iphone - ZBAR sdk 未在 iPhone 4s (ios 5.1) 上检测到 QRCODES...?

ios - 确定用户是在室内还是室外?