3

I have a very strange crash when using the Apple LLVM 3.0 compiler. So there is some code, that uses Assimp to load assets and create the scene (I've excluded all my code and even then it crashes):

aiScene* ai_scene = const_cast<aiScene*>(aiImportFileFromMemory(fileBuf, fInfo.uncompressed_size, aiProcessPreset_TargetRealtime_MaxQuality, NULL));

delete ai_scene;

Here is the screenshot of the stack trace for GCC:

enter image description here

And here is for LLVM:

enter image description here

In LLVM version destructor is called twice (and probably that's why I've got a crash).

I should also mention that all destructor code is located in header file and crashes only on device (tested on iPod 4 and iPad 2).

Is it a bug in LLVM compiler (probably in generation of arm assembly) or did I miss something?

Edit:

in case someone has similar problem use aiReleaseImport(scene) instead of delete scene;

Charles
  • 50,943
  • 13
  • 104
  • 142
Max
  • 16,679
  • 4
  • 44
  • 57

2 Answers2

3

You are not supposed to delete that pointer at all. Read the documentation. It clearly states that you should not attempt to free it in any way.

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().

And in addition, the documentation explicitly states that it's read-only, so do not const_cast the const away.

Puppy
  • 144,682
  • 38
  • 256
  • 465
  • as for the const_cast - this is deprecated code, and I will remove that soon (the scene is actually treated as const). – Max Nov 01 '11 at 15:36
  • thank you for pointing me the right direction. you were right about the delete operator. – Max Nov 01 '11 at 15:50
0

I had a similar problem earlier, and it was quite rare because I go no responses (other than my own) to that problem AppStore build crashes on launch on iPhone 3g and iPod Touch

It'd crash only on iPhone 3g, and on an old iPod touch.

Community
  • 1
  • 1
Nitin Alabur
  • 5,812
  • 1
  • 34
  • 52