OS X strange Crash

soulstorm
Posts: 5
Joined: Thu Sep 26, 2013 8:10 pm

OS X strange Crash

Post by soulstorm »

I have used Bullet a few days ago, in a Core i7 laptop with OS X Mountain Lion w/ Xcode 5 (Clang 5.0) successfully . However, with the same exact code and project, I am facing a big problem with runtime errors with bullet.

this is my (simplified for the sake of clarity of this post) code:

Code: Select all

int main(int argc, const char * argv[])
{				
	btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.)));
	return 0;
}
and this is my error:

Code: Select all

"Thread 1: EXC_BAD_ACCESS (code=EXC_I386_GPFLT)" . 
Backtrace:

Code: Select all

(lldb) bt
* thread #1: tid = 0x86f26, 0x000000010000c4a5 CommandBullet`btBoxShape::btBoxShape(btVector3 const&) + 181, queue = 'com.apple.main-thread, stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
    frame #0: 0x000000010000c4a5 CommandBullet`btBoxShape::btBoxShape(btVector3 const&) + 181
    frame #1: 0x000000010000136a CommandBullet`main(argc=1, argv=0x00007fff5fbff868) + 106 at main.cpp:16
    frame #2: 0x00007fff918e17e1 libdyld.dylib`start + 1
(lldb) 
I am using statically linked libraries produced by creating an Xcode project from source, using Cmake, and making absolutely no other alterations (Cmake was left with the default settings). The same procedure worked in my other computer, with very complex code (Core i7 macbook pro with Mountain Lion 10.8.5, nVidia GT650M) but in this computer (which is an iMac Core i5 OS X 10.8.5 AMD Radeon HD 6750M), I get runtime errors such as this, in various parts of the code, for no reason whatsoever.

- EDIT: I can run the samples fine but this simple code still refuses to run

I am hitting my head against the wall over this for a few hours now, and I still cannot figure out this issue. Could this have something to do with bit alignment that differs between processors for some reason?
soulstorm
Posts: 5
Joined: Thu Sep 26, 2013 8:10 pm

Re: OS X strange Crash

Post by soulstorm »

Anyone? I am still facing the issue, and I've been fighting with this for over two days. I did a fresh OS X format, still nothing.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: OS X strange Crash

Post by Erwin Coumans »

Generally it is very error-prone and a bad idea to link against pre-compiled libraries. It is better to simply add the Bullet source files in your project. Please try that first.

If that doesn't fix it, you better compare all the project setting differences between the working cmake/premake generated files and your own.

The crash could be due to SSE on non-aligned data.
You can disable SIMD/SSE on Apple Mac OSX, by commenting out some lines in Bullet/src/LinearMath/btScalar.h:

#if (defined (__APPLE__) && (!defined (BT_USE_DOUBLE_PRECISION)))
#if defined (__i386__) || defined (__x86_64__)
// #define BT_USE_SIMD_VECTOR3
// #define BT_USE_SSE
//BT_USE_SSE_IN_API is enabled on Mac OSX by default, because memory is automatically aligned on 16-byte boundaries
//if apps run into issues, we will disable the next line
// #define BT_USE_SSE_IN_API

This should not be necessary, because Mac OSX should align memory on 16 byte boundaries.

Perhaps move the btVector3 in its own line?

btVector3 halfExtents (btScalar(50.),btScalar(50.),btScalar(50.));
btCollisionShape* groundShape = new btBoxShape(halfExtents);
Anyone?
Most people are too busy with their own projects to help others with such issues, so you might have to figure it out all by yourself.
Good luck,
Erwin
soulstorm
Posts: 5
Joined: Thu Sep 26, 2013 8:10 pm

Re: OS X strange Crash

Post by soulstorm »

Most people are too busy with their own projects to help others with such issues, so you might have to figure it out all by yourself.
I hope I didn't come across as rude earlier. I know no one is obliged to give any help. I just was so frustrated I wasn't thinking clearly. I think I solved the problem, by creating a new project, transferring all the code, and linking against the libraries again. I think I accidentally linked the static libraries of 2.81 with headers from version 2.80, but I am not sure this was the problem yet. If it was, sorry for wasting anyone's time.

However, you sparked my interest. Why is it generally a bad idea to link against pre-compiled libraries? Inserting all this code into the project considerably increases compilation time in many cases, and it will not keep the project clear... But I may be wrong. Can you brief me what are the disadvantages of doing so?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: OS X strange Crash

Post by Erwin Coumans »

However, you sparked my interest. Why is it generally a bad idea to link against pre-compiled libraries?
Experiencing strange crashes, because the compiled library is not identical to the header files used.
Other people have linking issues, because the link library order has to be exactly right on some platforms (BulletSoftBody -> BulletDynamics -> BulletCollision -> LinearMath).
Some people mix debug versus release version of libraries, different versions of the library, different settings in the btScalar.h (double precision vs single precision, SSE/SIMD enabled/disabled).

Is is just a support burden, not worth the hassle. Compiling Bullet doesn't take very long.
soulstorm
Posts: 5
Joined: Thu Sep 26, 2013 8:10 pm

Re: OS X strange Crash

Post by soulstorm »

I see. To be fair I tried that as an alternative of including bullet into my project, but I was presented with many errors of missing headers. I just included the contents of the "src" folder. I will look more into it.