std::bad_alloc on instantiating btSequentialImpulseConstrain

Calder
Posts: 11
Joined: Fri May 15, 2009 10:01 pm

std::bad_alloc on instantiating btSequentialImpulseConstrain

Post by Calder »

I'm going through the hellish process of porting something to Windows, and have run into yet another show-stopping error that I have no clue how to solve. After four or five desperate help posts on various forums, I'm hopefully nearing the end of the interminable errors. Anyway, here's the first part of code I use to initialize Bullet:

Code: Select all

            int maxProxies = 1024;
            btVector3 worldMin(-10000,-10000,-10000);
            btVector3 worldMax(10000,10000,10000);
            mBroadphase = new btAxisSweep3(worldMin,worldMax,maxProxies);
            mConfig = new btDefaultCollisionConfiguration();
            mDispatcher = new btCollisionDispatcher(mConfig);
            mSolver = new btSequentialImpulseConstraintSolver();
            ...
It's the last line that causes the error, so everything after that is made irrelevant for now. It compiles fine, but when I go to run the application I get:

Code: Select all

Unhandled exception at 0x7643b727 in JD_Windows.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x003df060..
Sorry to waste everyone's time with this, but I've been bashing my head against for hours and am completely lost. Many thanks to anyone who can help out!
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: std::bad_alloc on instantiating btSequentialImpulseConstrain

Post by Erwin Coumans »

The code looks fine, so the problem seems to be elsewhere. Are you overriding the global memory allocator?

Have you tried building the Bullet demos on Windows, using the unmodified Bullet SDK and using the visual studio project files, or CMake?
Thanks,
Erwin
Calder
Posts: 11
Joined: Fri May 15, 2009 10:01 pm

Re: std::bad_alloc on instantiating btSequentialImpulseConstrain

Post by Calder »

Thanks for the quick reply!

I downloaded the source, built the examples, and placed the release and debug .lib files in their appropriate places. The frustrating thing is that the examples work, and if my code works too then the problem must lie in some weird Windows linking voodoo. (I'm very new to the whole Windows development scene, as you may have guessed.) There aren't supposed to be any dll files built, are there? The example apps didn't seem to need any, so I assumed mine wouldn't either.
Calder
Posts: 11
Joined: Fri May 15, 2009 10:01 pm

Re: std::bad_alloc on instantiating btSequentialImpulseConstrain

Post by Calder »

Image plz

:D
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: std::bad_alloc on instantiating btSequentialImpulseConstrain

Post by Erwin Coumans »

That kitten is in a painful situation :)

Please verify that the configuration properties are the same for the Bullet library and your own project. Just check them side by side.
In particular Project/Options/C++ options / Code Generation / Runtime library should be the same.

Alternatively, just add all the Bullet source files into your own project (all .cpp and .h files in the Bullet/src folder) and don't link against a .lib.

Hope this helps,
Erwin
Calder
Posts: 11
Joined: Fri May 15, 2009 10:01 pm

Re: std::bad_alloc on instantiating btSequentialImpulseConstrain

Post by Calder »

I'm trying to avoid adding all 1 million lines or so of Bullet code to by project, but it's nice to have as a last resort.

I'd already compared the project options against the bullet demos to no avail, but I'm guessing that glossed over the central problem because they link against the libraries differently? Maybe? Anyway, here's the break-down of differences between the two:
Debug Information Format: /ZI vs /Zi
Preprocessor Definitions: WIN32;DEBUG vs. _DEBUG;_LIB;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;WIN32
Enable C++ Exceptions: Yes vs. No
Runtime Library: /MDd vs. MTd
Treat wchar_t as Built-in Type: Yes vs. No
Enable Run-Time Type Info: Yes vs. No
Compile As: C++ Code vs. Default

I'm going to try changing the Runtime Library and see if that fixes it. Thanks again for the help!

EDIT: Static linking is an utter mess. I'm going to try compiling Bullet as a DLL instead.

EDIT2: Woah. I just ran into a bunch more problems. I'll get back to this when I've understand a little more...

EDIT3: There is a bug in another one of the libraries I'm using that causes it to crash before I reach Bullet now, so once that's worked out I'll get to try the Bullet DLL