Hello World example crashes
-
- Posts: 8
- Joined: Wed Jan 14, 2009 6:00 pm
Hello World example crashes
UPDATE:
i tried compiling 2.69 with the same setup and it doesn't crash, it works. what gives? is 2.73 incompatible with vs 2008? and, will i miss any important new features by using this older version?
----
hello all.
i have a bit of trouble with bullet..
basically, when i try to add a rigid body, it crashes.
i've tried both writing my own code and using the exact one from the hello world example on the wiki, but i always get this:
Unhandled exception at 0x004a7a2d in cupcake.exe: 0xC0000005: Access violation reading location 0x5b845c33.
the 'reading location' number is always that same one.
the debugger points to the end of the function void btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body)
when i do dynamicsWorld->addRigidBody(fallRigidBody);
i compiled bullet 2.73 using visual c++ express 2008, from the vs8 project files (auto-converted to vs9), and i'm using that to compile the programs too. the demos that come with bullet, however, do not crash even though i compiled them myself too..
i'm running winxp 32-bit. if anyone could shed some light on this, i'd appreciate that very much.
thanks.
i tried compiling 2.69 with the same setup and it doesn't crash, it works. what gives? is 2.73 incompatible with vs 2008? and, will i miss any important new features by using this older version?
----
hello all.
i have a bit of trouble with bullet..
basically, when i try to add a rigid body, it crashes.
i've tried both writing my own code and using the exact one from the hello world example on the wiki, but i always get this:
Unhandled exception at 0x004a7a2d in cupcake.exe: 0xC0000005: Access violation reading location 0x5b845c33.
the 'reading location' number is always that same one.
the debugger points to the end of the function void btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body)
when i do dynamicsWorld->addRigidBody(fallRigidBody);
i compiled bullet 2.73 using visual c++ express 2008, from the vs8 project files (auto-converted to vs9), and i'm using that to compile the programs too. the demos that come with bullet, however, do not crash even though i compiled them myself too..
i'm running winxp 32-bit. if anyone could shed some light on this, i'd appreciate that very much.
thanks.
-
- Posts: 508
- Joined: Fri May 30, 2008 2:51 am
- Location: Ossining, New York
Re: Hello World example crashes
I had no problems with 2.73, vc++2008 and xp pro 32bit
-
- Posts: 8
- Joined: Wed Jan 14, 2009 6:00 pm
Re: Hello World example crashes
well, in case anyone else happens to come across this problem..
it happened when i used bullet together with irrlicht.
when using ogre instead, it does not crash.
some kind of incompatability?
it happened when i used bullet together with irrlicht.
when using ogre instead, it does not crash.
some kind of incompatability?
-
- Posts: 508
- Joined: Fri May 30, 2008 2:51 am
- Location: Ossining, New York
Re: Hello World example crashes
probably one of the myriad of irritating msvc compiler options wasn't right
-
- Posts: 8
- Joined: Wed Jan 14, 2009 6:00 pm
Re: Hello World example crashes
actually, i tried compiling the hello world on a completely clean windows + visual studio installation and it still crashes in the same spot, with the same error.
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Hello World example crashes
You might be compiling the wrong Hello World.
This updated Irrlicht 1.5, Bullet 2.74 test works just fine.
Hope this helps,
Erwin
This updated Irrlicht 1.5, Bullet 2.74 test works just fine.
Hope this helps,
Erwin
-
- Posts: 8
- Joined: Wed Jan 14, 2009 6:00 pm
Re: Hello World example crashes
well, i was trying this example: http://www.bulletphysics.com/mediawiki- ... ello_World
with 2.74, it still crashes, but i made a new project using the code from the irrtest (which works for me), minus the irrlicht code, and that runs too.
however, when i try to place RigidBody objects inside a class and adding arbitrary numbers of them to the world, it starts crashing.
basically it goes like this, when i try to add new RigidBody-s to the world:
- sometimes it works.
- sometimes it crashes.
for a while it would crash after adding 3 of them, now it's after i add 11 or 12, ... i just don't get it.
the worst part is that i copied this new code directly from irrtest, which works, while my program crashes.
i'm linking to the same runtime library, creating the world and the bodies using the same code..
i think i'll just give up. or go back to 2.69, which doesn't completely work for me either, only with some workarounds (it crashes when i try to delete a RigidBody, it won't work together with ogre in debug mode, only release..)
i might add that i'm using vc9 (2008), in case that matters.
with 2.74, it still crashes, but i made a new project using the code from the irrtest (which works for me), minus the irrlicht code, and that runs too.
however, when i try to place RigidBody objects inside a class and adding arbitrary numbers of them to the world, it starts crashing.
basically it goes like this, when i try to add new RigidBody-s to the world:
- sometimes it works.
- sometimes it crashes.
for a while it would crash after adding 3 of them, now it's after i add 11 or 12, ... i just don't get it.
the worst part is that i copied this new code directly from irrtest, which works, while my program crashes.
i'm linking to the same runtime library, creating the world and the bodies using the same code..
i think i'll just give up. or go back to 2.69, which doesn't completely work for me either, only with some workarounds (it crashes when i try to delete a RigidBody, it won't work together with ogre in debug mode, only release..)
i might add that i'm using vc9 (2008), in case that matters.
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Hello World example crashes
What is the full call stack at the crash?
Can you share your crashing project?
Thanks,
Erwin
Can you share your crashing project?
Thanks,
Erwin
-
- Posts: 8
- Joined: Wed Jan 14, 2009 6:00 pm
Re: Hello World example crashes
here, i tried to make a miniature project which displays this crashing behaviour.
right now i'm using 2.73, however, with 2.74 earlier i was getting the same kinds of errors.
some notes:
besides the #pragmas at the top, i haven't changed any of the default settings in a new empty project in VS.
it only crashes after i've created a certain amount of objects, i didn't check the count now except that setting NumObjects to 1 doesn't crash, and 50 does crash.
it crashes in different ways depending on whether i compile as debug (linking with debug libs, as in the code above) or with release (with release libs).
in debug mode, everything seems to work (for once) except for deleting objects in the cleanup iterator, where it crashes with:
on line 31 of btAlignedAllocator.cpp.
deleting the MotionState works but when i try to delete the RigidBody, i get it.
in release mode, it crashes differently depending on if i use a list, a vector, or nothing to store the "thing" instances.
with a list, it crashes on line 93 (m_collisionObjects.push_back(... ) in btCollisionWorld.cpp with:
with a vector, it points to line 177 of btDbvtBroadphase.cpp (proxy->stage = m_stageCurrent) with:
without storing the references, just creating a bunch of class instances, it points to line 454 of btDiscreteDynamicsWorld.cpp with:
am i just creating/storing my RigidBody references in an incorrect way? the messages seem to indicate that, but i'm not exactly an expert..
here's some lines from the call stack tab after one of the crashes:
right now i'm using 2.73, however, with 2.74 earlier i was getting the same kinds of errors.
Code: Select all
// linker options
#pragma comment(linker, "/NODEFAULTLIB:LIBCMTD")
#pragma comment(lib, "libbulletcollision_d.lib")
#pragma comment(lib, "libbulletdynamics_d.lib")
#pragma comment(lib, "libbulletmath_d.lib")
// includes
#include <btBulletCollisionCommon.h>
#include <btBulletDynamicsCommon.h>
#include <iostream>
#include <list>
using namespace std;
btDiscreteDynamicsWorld *World;
// represents a hypothetical game object
class thing
{
public:
btRigidBody* RigidBody;
thing(btVector3 TPosition)
{
// Set the initial position of the object
btTransform Transform;
Transform.setIdentity();
Transform.setOrigin(TPosition);
btDefaultMotionState *MotionState = new btDefaultMotionState(Transform);
// Create the shape
btVector3 HalfExtents(5.0f,5.0f,5.0f);
btCollisionShape *Shape = new btBoxShape(HalfExtents);
// Add mass
btVector3 LocalInertia;
Shape->calculateLocalInertia(10.0f, LocalInertia);
// Create the rigid body object
RigidBody = new btRigidBody(10.0f, MotionState, Shape, LocalInertia);
// Add it to the world
World->addRigidBody(RigidBody);
}
};
// ******
list<thing*> things;
int main() {
cout << "Bullet Physics Library SDK Version " << btGetVersion() << "\n";
// Initialize bullet
btDefaultCollisionConfiguration *CollisionConfiguration = new btDefaultCollisionConfiguration();
btBroadphaseInterface *BroadPhase = new btAxisSweep3(btVector3(-1000, -1000, -1000), btVector3(1000, 1000, 1000));
btCollisionDispatcher *Dispatcher = new btCollisionDispatcher(CollisionConfiguration);
btSequentialImpulseConstraintSolver *Solver = new btSequentialImpulseConstraintSolver();
World = new btDiscreteDynamicsWorld(Dispatcher, BroadPhase, Solver, CollisionConfiguration);
// add some objects
cout << "* adding objects..\n";
int NumObjects = 50;
for(int i=0;i<NumObjects;i++)
{
thing* t = new thing(btVector3(0,20.0f * i,0));
things.push_back(t);
}
// step the world a bit
cout << "* stepping";
for(int i =0;i<200;i++)
{
cout << ".";
World->stepSimulation(1.0f/60.0f, 10);
}
cout << "done.\n* cleaning up";
// clean up
for(list<thing*>::iterator it=things.begin();it!=things.end();++it)
{
cout << ".";
thing* t = *it;
World->removeRigidBody(t->RigidBody);
delete t->RigidBody->getMotionState();
delete t->RigidBody->getCollisionShape();
delete t->RigidBody;
}
delete World;
delete Solver;
delete Dispatcher;
delete BroadPhase;
delete CollisionConfiguration;
cout << "\ndone.";
// done
return 0;
}
besides the #pragmas at the top, i haven't changed any of the default settings in a new empty project in VS.
it only crashes after i've created a certain amount of objects, i didn't check the count now except that setting NumObjects to 1 doesn't crash, and 50 does crash.
it crashes in different ways depending on whether i compile as debug (linking with debug libs, as in the code above) or with release (with release libs).
in debug mode, everything seems to work (for once) except for deleting objects in the cleanup iterator, where it crashes with:
Code: Select all
HEAP[btest.exe]: Heap block at 00037CD8 modified at 00037EE3 past requested size of 203
deleting the MotionState works but when i try to delete the RigidBody, i get it.
in release mode, it crashes differently depending on if i use a list, a vector, or nothing to store the "thing" instances.
with a list, it crashes on line 93 (m_collisionObjects.push_back(... ) in btCollisionWorld.cpp with:
Code: Select all
First-chance exception at 0x7c902c53 in btest.exe: 0xC0000005: Access violation writing location 0x00037000.
First-chance exception at 0x00429826 in btest.exe: 0xC0000005: Access violation writing location 0x00000004.
Unhandled exception at 0x00429826 in btest.exe: 0xC0000005: Access violation writing location 0x00000004.
Code: Select all
First-chance exception at 0x7c902c53 in btest.exe: 0xC0000005: Access violation writing location 0x007f5000.
First-chance exception at 0x0040fc5b in btest.exe: 0xC0000005: Access violation writing location 0x0000003c.
Unhandled exception at 0x0040fc5b in btest.exe: 0xC0000005: Access violation writing location 0x0000003c.
Code: Select all
HEAP[btest.exe]: Heap missing last entry in committed range near 372a8
here's some lines from the call stack tab after one of the crashes:
Code: Select all
> btest.exe!btDiscreteDynamicsWorld::addRigidBody(btRigidBody * body=0x000372c0) Line 454 + 0xb bytes C++
btest.exe!thing::thing(btVector3 TPosition={...}) Line 45 C++
btest.exe!main() Line 68 + 0x63 bytes C++
btest.exe!___CxxFrameHandler3() + 0xec bytes C++
btest.exe!__SEH_epilog4() + 0x13 bytes Asm
kernel32.dll!7c839ac0()
-
- Posts: 9
- Joined: Fri Mar 20, 2009 3:57 am
Re: Hello World example crashes
Sorry if this is resurrecting a dead post, I'm at my wits end. Have you found an answer to this yet?
I posted a similar thread http://bulletphysics.com/Bullet/phpBB3/ ... php?t=3368 , which has more in depth information about my problems. I got that one working with a simple #define WIN32 (that surprised me, I was just doing random things...), but now it's coming up again when I'm trying to use BtOgre.
It breaks on a fairly simple line:
(doing a _heapchk() after this line throw an error about corruption.
here's the stack trace:
From what I understand, btTriangleMesh overloads the new operator with a 16-bit aligned operator. What this means, I don't totally know (it basically allocates memory, rounding up to the nearest 16 bits, right?)...could there be a bug in here that causes it to sometimes round down instead of up in certain circumstances or something, thus overwriting the end of itself on allocation? I really don't know...I'm totally guessing here, this is over my head
EDIT: Ok, after some playing with the above sample code (from lickstab), I replicated the problem. After adding #define WIN32, I got the following error:
So it turned out I was barking up the right tree with the attribute alignment stuff, but I lack understanding. Is there any doco on how the attribute alignment stuff works, so I can keep it mind when making my classes? What rules should I follow? My solution has now been to make sure I'm (pretty much) always dealing with pointers, as that seems to keep me out of trouble...
I posted a similar thread http://bulletphysics.com/Bullet/phpBB3/ ... php?t=3368 , which has more in depth information about my problems. I got that one working with a simple #define WIN32 (that surprised me, I was just doing random things...), but now it's coming up again when I'm trying to use BtOgre.
It breaks on a fairly simple line:
Code: Select all
btTriangleMesh *trimesh = new btTriangleMesh();
Code: Select all
HEAP[TestOgreProject.exe]: Heap block at 043D9568 modified at 043D9654 past requested size of e3
Windows has triggered a breakpoint in TestOgreProject.exe.
This may be due to a corruption of the heap, and indicates a bug in TestOgreProject.exe or any of the DLLs it has loaded.
Code: Select all
ntdll.dll!7c90120e()
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
ntdll.dll!7c96c201()
ntdll.dll!7c95d454()
ntdll.dll!7c96bd1d()
ntdll.dll!7c96c956()
ntdll.dll!7c96039f()
msvcr80d.dll!malloc(unsigned int nSize=4128768) Line 154 + 0x15 bytes C++
kernel32.dll!7c85f8d7()
msvcr80d.dll!_heapchk() Line 96 + 0x10 bytes C
TestOgreProject.exe!BtOgre::VertexIndexToShape::createTrimesh() Line 321 C++
> TestOgreProject.exe!BtOgreTestApplication::createScene() Line 186 + 0xb bytes C++
TestOgreProject.exe!ExampleApplication::setup() Line 140 C++
TestOgreProject.exe!ExampleApplication::go() Line 89 + 0xd bytes C++
TestOgreProject.exe!WinMain(HINSTANCE__ * hInst=0x00400000, HINSTANCE__ * __formal=0x00000000, char * strCmdLine=0x00151f39, HINSTANCE__ * __formal=0x00000000) Line 236 + 0x8 bytes C++
TestOgreProject.exe!__tmainCRTStartup() Line 589 + 0x35 bytes C
TestOgreProject.exe!WinMainCRTStartup() Line 414 C
kernel32.dll!7c817067()
EDIT: Ok, after some playing with the above sample code (from lickstab), I replicated the problem. After adding #define WIN32, I got the following error:
Code: Select all
error C2719: 'TPosition': formal parameter with __declspec(align('16')) won't be aligned
-
- Posts: 8
- Joined: Wed Jan 14, 2009 6:00 pm
Re: Hello World example crashes
hmm, i'm afraid my "solution" was to stop using bullet and switch to newton (using ogrenewt). it works great.
sorry =/
sorry =/
-
- Posts: 10
- Joined: Mon Mar 30, 2009 2:54 am
Re: Hello World example crashes
I'm also having this same problem with MSVC++ 2008. Same hello world program also. I'll try an older version of Bullet.
Edit: 2.69 seems to work fine out of the box.
Edit: 2.69 seems to work fine out of the box.
-
- Posts: 2
- Joined: Tue Apr 14, 2009 10:09 pm
Re: Hello World example crashes
Hello!
I've found the solution to this problem.
In order to make it work, just add "WIN32" (without quotes) to the Preprocessor Definitions in the Project Properties -> C/C++ -> Preprocessor.
Hope it helps! (It helped me at least).
Have no problems so far, but in case anything appears to go wrong, i guess a way to solve it, is just to check the difference between your project and the working demo projects supplied in the sdk. This is the way how i found the "win32" thing.
xwipeoutx wrote about win32 before, but my idea in the worst case scenario is searching for the differences in the project files.
I've found the solution to this problem.
In order to make it work, just add "WIN32" (without quotes) to the Preprocessor Definitions in the Project Properties -> C/C++ -> Preprocessor.
Hope it helps! (It helped me at least).
Have no problems so far, but in case anything appears to go wrong, i guess a way to solve it, is just to check the difference between your project and the working demo projects supplied in the sdk. This is the way how i found the "win32" thing.
xwipeoutx wrote about win32 before, but my idea in the worst case scenario is searching for the differences in the project files.
-
- Posts: 11
- Joined: Fri May 15, 2009 10:01 pm
Re: Hello World example crashes
I am at my wit's end over this one, any help would be greatly appreciated. I've tried the WIN32 define to no avail, and I'm really have no idea where to go from here. Please, if anyone could fix or even explain the issue, that would be amazing!
EDIT: If it makes a difference, I'm using a 64-bit processor...
EDIT2: Changing my function from
to
did the trick!
EDIT: If it makes a difference, I'm using a 64-bit processor...
EDIT2: Changing my function from
Code: Select all
void setPosition (btVector3 pos);
Code: Select all
void setPosition (const btVector3& pos);
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Hello World example crashes
I'm suprised that WIN32 isn't a built-in definition, or added by MSVC by default.
We should look into fixing this, or at least put it in the user manual.
Thanks,
Erwin
We should look into fixing this, or at least put it in the user manual.
Thanks,
Erwin