Crash on Android during binary FBX import #24

Closed
jdduke opened this Issue Apr 2, 2013 · 20 comments

Comments

Projects
None yet
Contributor

jdduke commented Apr 2, 2013

Using any of the NDK flavors of gcc (4.4, 4.6 and 4.7) for Android, with both STLport and libstdc++, I get a crash in one of ParseTokenAsID or ParseTokenAsFloat during binary FBX import. Below is a typical crash dump.

I/DEBUG ( 124): signal 7 (SIGBUS), code 128 (?), fault addr 00000000
I/DEBUG ( 124): r0 5d59a4d8 r1 6200d7d0 r2 0000004c r3 624114fd
I/DEBUG ( 124): r4 5d5bcc38 r5 5d5b7640 r6 5d5b7678 r7 623263e8
I/DEBUG ( 124): r8 5d59a4d8 r9 623263f0 sl 00000000 fp 62326960
I/DEBUG ( 124): ip 0000004f sp 623262e8 lr 61f5176f pc 61f3a228 cpsr 00000030
I/DEBUG ( 124): d0 697463656e6e6f43 d1 636146656c616362
I/DEBUG ( 124): d2 5d59a4a85d59a46a d3 5d59a4d85d59a465
I/DEBUG ( 124): d4 5d59a3885d59a370 d5 5d59a3b85d59a3a0
I/DEBUG ( 124): d6 5d59a3e85d59a3d0 d7 5d59a4185d59a400
I/DEBUG ( 124): d8 0000000000000000 d9 0000000000000000
I/DEBUG ( 124): d10 0000000000000000 d11 0000000000000000
I/DEBUG ( 124): d12 0000000000000000 d13 0000000000000000
I/DEBUG ( 124): d14 0000000000000000 d15 0000000000000000
I/DEBUG ( 124): d16 415c9c3800000000 d17 7e37e43c8800759c
I/DEBUG ( 124): d18 0000000000000002 d19 0000000000000000
I/DEBUG ( 124): d20 0000000000000000 d21 00000000bca237c3
I/DEBUG ( 124): d22 3f800000bf7fffe0 d23 3f800000bf7aee42
I/DEBUG ( 124): d24 000000003b360b61 d25 0000000000000000
I/DEBUG ( 124): d26 bae72ae400000000 d27 0000000000000000
I/DEBUG ( 124): d28 0000000000000000 d29 00000000bca237c3
I/DEBUG ( 124): d30 3f800000bf7fffe0 d31 3f800000bf7aee42
I/DEBUG ( 124): scr 80000096
I/DEBUG ( 124):
I/DEBUG ( 124): backtrace:
I/DEBUG ( 124): #00 pc 0029e228 /data/app-lib//libassimp.so (Assimp::FBX::ParseTokenAsID(Assimp::FBX::Token const&)+139)
I/DEBUG ( 124): #1 pc 002b576b /data/app-lib/
/libassimp.so (Assimp::FBX::Document::ReadConnections()+194)
I/DEBUG ( 124):
I/DEBUG ( 124): stack:
I/DEBUG ( 124): 623262a8 00000002
I/DEBUG ( 124): 623262ac 61f90c7c /data/app-lib//libassimp.so (std::string::Rep::S_create(unsigned int, unsigned int, std::allocator const&)+100)
I/DEBUG ( 124): 623262b0 5d5bcc44
I/DEBUG ( 124): 623262b4 61f91b88 /data/app-lib/
/libassimp.so (char* std::string::S_construct<char const*>(char const, char const
, std::allocator const&, std::forward_iterator_tag)+76)
I/DEBUG ( 124): 623262b8 00000000
I/DEBUG ( 124): 623262bc 623262f8
I/DEBUG ( 124): 623262c0 00000000
I/DEBUG ( 124): 623262c4 5d59a4a8
I/DEBUG ( 124): 623262c8 623263e8
I/DEBUG ( 124): 623262cc 61f91c20 /data/app-lib/
/libassimp.so (std::basic_string<char, std::char_traits, std::allocator >::basic_string(char const_, unsigned int, std::allocator const&)+28)
I/DEBUG ( 124): 623262d0 623262f8
I/DEBUG ( 124): 623262d4 61f3a0f5 /data/app-lib//libassimp.so (Assimp::FBX::ParseTokenAsString(Assimp::FBX::Token const&, char const&)+144)
I/DEBUG ( 124): 623262d8 c0000000
I/DEBUG ( 124): 623262dc 5d5bcc38
I/DEBUG ( 124): 623262e0 e3a070ad
I/DEBUG ( 124): 623262e4 ef9000ad
I/DEBUG ( 124): #00 623262e8 62326350
I/DEBUG ( 124): 623262ec 61f3a149 /data/app-lib//libassimp.so (Assimp::FBX::ParseTokenAsString(Assimp::FBX::Token const&)+32)
I/DEBUG ( 124): 623262f0 5d5bcc38
I/DEBUG ( 124): 623262f4 5d5b7640
I/DEBUG ( 124): 623262f8 5d5b7678
I/DEBUG ( 124): 623262fc 623263e
I/DEBUG ( 124): 62326300 623263ec
I/DEBUG ( 124): 62326304 623263f0
I/DEBUG ( 124): 62326308 00000000
I/DEBUG ( 124): 6232630c 61f5176f /data/app-lib/
/libassimp.so (Assimp::FBX::Document::ReadConnections()+198)
I/DEBUG ( 124): 62326310 00000008
I/DEBUG ( 124): 62326314 5d5b76a8
I/DEBUG ( 124): 62326318 00000000
I/DEBUG ( 124): 6232631c 00000000
I/DEBUG ( 124): 62326320 5d5b7e28
I/DEBUG ( 124): 62326324 62086adc

@ghost ghost assigned acgessler Apr 3, 2013

I also can't import FBX with assimp on Android

I don't have the full stack trace but I have this error:
09-13 09:24:26.365 6053-6053/com.qualcomm.QCARSamples.FrameMarkers A/libc﹕ Fatal signal 7 (SIGBUS) at 0x746421ea (code=1), thread 6053 (es.FrameMarkers)

I think it may be related

Contributor

sherief commented Sep 23, 2013

Can we get the FBX file(s) you used so we can reproduce?

Contributor

jdduke commented Sep 23, 2013

Any of the binary FBX files in our test data folder should trigger it.

@kimkulling kimkulling assigned kimkulling and unassigned acgessler Mar 6, 2014

I'm interested in assimp releasing a new version of their software so I will try to push this oldest issues a bit.

Is there any news on this issue since the last comment?

Thanks in advance.

I've also ran into this issue as well. Any update?

I have assimp loading other formats such as .obj but it's failing on fbx.

Thanks

same here with:

const struct aiScene* assimpScene = importer.ReadFileFromMemory((const void *) buffer,
lenght,
aiProcess_Triangulate | aiProcess_GenSmoothNormals,
"fbx");

solved

in FBXParser.cpp -> ParseTokenAsFloat

in android there is a sigbus because bad memory aligment, i've solved it with memcpy //commented parts are the previous ones

if(t.IsBinary())
{
const char* data = t.begin();
if (data[0] != 'F' && data[0] != 'D') {
err_out = "failed to parse F(loat) or D(ouble), unexpected data type (binary)";
return 0.0f;
}

    if (data[0] == 'F') {
        ai_assert(t.end() - data == 5);
        // no byte swapping needed for ieee floats
        float returnFloat;
        memcpy(&returnFloat, data+1, sizeof(float));
        return returnFloat;//*reinterpret_cast<const float*>(data+1);
    }
    else {
        ai_assert(t.end() - data == 9);
        // no byte swapping needed for ieee floats
        double returnFloat;
        memcpy(&returnFloat, data+1, sizeof(double));
        return (float) returnFloat;//static_cast<float>(*reinterpret_cast<const double*>(data+1));
    }
}
Owner

acgessler commented May 15, 2014

Awesome finding.

I strongly suspect that other loaders are suspected of similar code as well ...

currently i've integrated assimp to my c++ opengl engine for android and ios, if i found any other issue i will post it

my patch is a little uggly but it was a hotfix, how you will integrate it in a cleaner way?

Owner

acgessler commented May 22, 2014

I think we'll go with memcpy.

reinterpret_cast breaks strict aliasing rules. The union trick is allowed by many compilers, but strictly speaking it is a violation of a rule that writing to an union with type A and directly thereafter reading with type B is undefined behaviour as well.

@acgessler acgessler closed this in becd298 May 22, 2014

Owner

acgessler commented May 22, 2014

Thanks! Very glad to solve this. Re-open if the issue persists (I don't have the means of checking on Android right now ... )

Contributor

jdduke commented Aug 12, 2014

I've noticed a number of other places in FBXParser.cpp where we reinterpret_cast doubles, uint64s, etc... Are they not also candidates for the memcpy workaround?

Owner

acgessler commented Aug 12, 2014

Frankly, yes, almost every reinterpret_cast in the entire library should be a candidate. I just saw there is plenty of them.

@acgessler acgessler reopened this Aug 12, 2014

Any update? Still got crash if loading fbx files on Android.

Member

turol commented May 22, 2015

You can use Clang's undefined sanitizer to debug this on desktop. It will shout at you whenever you do unaligned loads. GCC 5 should also have this feature. You might have to use Linux though, not sure what Clang windows status is.

vinjn commented Aug 6, 2015

I have also experienced this issue - binary fbx file can't be loaded on Android.
I have narrowed down the problem to buggy behavior of AndroidJNIIOSystem.
https://github.com/assimp/assimp/blob/master/port/AndroidJNI/AndroidJNIIOSystem.cpp

By using irrlicht and leveraging its filesystem interface, I have solved the problem.
https://github.com/zaki/irrlicht/blob/ogl-es/source/Irrlicht/Android/CAndroidAssetReader.cpp

Hi, I'm getting a similar error, however the fixes mentioned here are applied.
I'm using the compiled .so of the latest version of assimp.

I/DEBUG(191): Revision: '11'
I/DEBUG(191): ABI: 'arm'
I/DEBUG(191): signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr 0x9c79f32a
I/DEBUG(191): r0 9c79f332 r1 a37ad0b4 r2 9c79f332 r3 9c79f32a
I/DEBUG(191): r4 b9a20c10 r5 9caef1c0 r6 9c4b5008 r7 00000000
I/DEBUG(191): r8 b99a7c50 r9 a37ad838 sl b98e5eb0 fp a37ad094
I/DEBUG(191): ip 00000000 sp a37ad060 lr 9d0642e0 pc 9d064328 cpsr 600f0010
I/DEBUG(191): backtrace:
I/DEBUG(191): #00 pc 008c4328 /data/app/lib/arm/libAssimp32.so (Assimp::FBX::ParseTokenAsID(Assimp::FBX::Token const&, char const_&)+260)
I/DEBUG(191): #1 pc 008fb350 /data/app/lib/arm/libAssimp32.so (Assimp::FBX::Document::ReadObjects()+988)
I/DEBUG(191): #2 pc 008f9874 /data/app/lib/arm/libAssimp32.so (Assimp::FBX::Document::Document(Assimp::FBX::Parser const&, Assimp::FBX::ImportSettings const&)+276)
I/DEBUG(191): #3 pc 008c23d8 /data/app/lib/arm/libAssimp32.so (Assimp::FBXImporter::InternReadFile(std::string const&, aiScene_, Assimp::IOSystem_)+860)
I/DEBUG(191): #4 pc 0033d5fc /data/app/lib/arm/libAssimp32.so (Assimp::BaseImporter::ReadFile(Assimp::Importer const_, std::string const&, Assimp::IOSystem_)+244)
I/DEBUG(191): #5 pc 00353a9c /data/app/lib/arm/libAssimp32.so (Assimp::Importer::ReadFile(char const_, unsigned int)+1920)
I/DEBUG(191): #6 pc 0032ad98 /data/app/lib/arm/libAssimp32.so (aiImportFileExWithProperties+376)

Any suggestions? Thanks in advance.

Owner

kimkulling commented Mar 17, 2016

I guess these errors are caused by the dynamic cast stuff done in the code. We haven't fixed all places until now.

@kimkulling kimkulling added the bug label Jul 11, 2017

@kimkulling kimkulling modified the milestones: Release 4.1, assimp4-rc Jul 11, 2017

Owner

kimkulling commented Jan 6, 2018

See #1686

Owner

kimkulling commented Jan 6, 2018

Closed by #1686

@kimkulling kimkulling closed this Jan 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment