Sign in to follow this  

ODE: running out of stack space

This topic is 4667 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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[i].surface.mode = dContactBounce | dContactSoftCFM;
contact[i].surface.mu = dInfinity;
contact[i].surface.mu2 = 0;
contact[i].surface.bounce = 0.1;
contact[i].surface.bounce_vel = 0.1;
contact[i].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).

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites

This topic is 4667 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this