ODE: running out of stack space

Started by
6 comments, last by sit 19 years, 1 month ago
I keep getting an error that I'm out of stack space, despite the fact that I really only have two boxes and a plane in my simulation. Code follows.

//////////////////////////////////////////////////////////////////////////////////////////
// Name: Step
// Desc: Takes one step in the physics simulation
// Notes: 
// ToFix: 
//////////////////////////////////////////////////////////////////////////////////////////
void PhysicsManager::Step()
{
	dWorldStep(m_world, m_timer->getDeltaTime());

	dSpaceCollide (m_space, &m_ids, &CollideCallback);
}

For testing reasons, CollideCallback is just a return statement. Where should I start looking for something that would cause this error? Commenting out the dSpaceCollide makes my program run flawlessly.
Advertisement
Endless recursion?
If I recall correctly, ODE uses a recursive solver for collisions. There should be a way to increase the stack space (I forget how exactly). Be sure to check out ODE's documentation for help on this. I doubt you are dealing with infinite recursion, but sometimes the recursive solver does try to perform a large number of recursive calls when collisions get complicated and overflows the stack.
You probably weren't looking for this type of advice, but if you're not too far along you could always give Novodex a try. Its free for non-commericial use and in my experiance causes far less hair pulling than ODE. I started with ODE but after running into problem after problem I decided it was crap. This was a couple years ago, so I'm sure it's much better, but I thought I'd point out that it's very possible that it's not something you're doing wrong.
It can't be the recursion depth, can it? I just have a box and a plane right now. I hit the problem whenever two things collide... is there some mistake that I should at least be looking for?
Yes, ODE uses a recursive solver AFAIK (or at least by default). We ran into this exact same problem last year. Theres a compiler flag you can set in visual studio (under project settings) to force a min stack space. We had to set it to like 80mb to get one level working.
I don't think it's a "legitimate" problem, though. I upped the stack to 40mb just to make sure, but I get the same error. To recap: I have one plane, one box and some gravity. I really shouldn't be getting this error.

Is there a "doh!" setting that I may have forgotten about? I'll just post the rest of the code.

PhysicsManager::PhysicsManager(void){	m_world=dWorldCreate();	m_timer=Timer::getInstance();	Entity::m_world=m_world;	dWorldSetGravity (m_world, GRAVITY_X, GRAVITY_Y, GRAVITY_Z);	m_space= dSimpleSpaceCreate (0);	Entity::m_space=m_space;	m_joints=dJointGroupCreate(0);	dWorldSetCFM (m_world,1e-5);	dWorldSetAutoDisableFlag (m_world,1);	dWorldSetContactMaxCorrectingVel (m_world,0.1);	dWorldSetContactSurfaceLayer (m_world,0.001);	m_ids.world=m_world;	m_ids.joints=m_joints;	m_ids.space=m_space;	dGeomID plane= dCreatePlane (m_space, 0, 1, 0, 0);}PhysicsManager::~PhysicsManager(void){	dWorldDestroy(m_world);	dJointGroupDestroy (m_joints);	dCloseODE();}static void CollideCallback(void *data, dGeomID o1, dGeomID o2){	IDBunch b=*((IDBunch*)data);	int i;	// exit without doing anything if the two bodies are connected by a joint	dBodyID b1 = dGeomGetBody(o1);	dBodyID b2 = dGeomGetBody(o2);	if (b1 && b2 && dAreConnectedExcluding (b1,b2,dJointTypeContact)) return;	dContact contact[MAX_CONTACTS];   // up to MAX_CONTACTS contacts per box-box	for (i=0; i<MAX_CONTACTS; i++) 	{		contact.surface.mode = dContactBounce | dContactSoftCFM;		contact.surface.mu = dInfinity;		contact.surface.mu2 = 0;		contact.surface.bounce = 0.1;		contact.surface.bounce_vel = 0.1;		contact.surface.soft_cfm = 0.01;	}	if (int numc = dCollide (o1,o2,MAX_CONTACTS,&contact[0].geom, sizeof(dContact))) 	{		dMatrix3 RI;		dRSetIdentity (RI);		const dReal ss[3] = {0.02,0.02,0.02};		for (i=0; i<numc; i++) 		{			dJointID c = dJointCreateContact (b.world,b.joints,contact+i);			dJointAttach (c,b1,b2);		}	}}


Entity::Entity():m_translation(0.0, 0.0, 0.0), m_texture(0){	m_bodyID= dBodyCreate (m_world);}EntityCube::EntityCube(float w, float h, float len):m_widthOverTwo(w*0.5f), m_heightOverTwo(h*0.5f), m_lengthOverTwo(len*0.5f){	m_renderModel=new RenderCube(m_widthOverTwo, m_heightOverTwo, m_lengthOverTwo);	CalcAABB();	SetPhysics();}void EntityCube::SetPhysics(){	m_geomID = dCreateBox (m_space, 2*m_widthOverTwo, 2*m_heightOverTwo, 2*m_lengthOverTwo);	dGeomSetBody (m_geomID, m_bodyID);}


I think the problem is in the callback function... if I stick a return statement in there, the program runs fine (sans collisions, of course).
Quote:Original post by Ratman
Yes, ODE uses a recursive solver AFAIK (or at least by default). We ran into this exact same problem last year. Theres a compiler flag you can set in visual studio (under project settings) to force a min stack space. We had to set it to like 80mb to get one level working.

this is offtopic for the OP [he has another problem if a collision between 2 objects results in a crash]

but you should try the quick solver [look at the test_crash.cpp demo]

oh, and some platforms [like linux] will let the stack grow unlike windows with visual studio...

This topic is closed to new replies.

Advertisement