[ODE] Stack overflow

Nate W coding at natew.com
Wed Jan 29 22:34:01 2003


On Wed, 29 Jan 2003, Marco Grubert wrote:

> when stress-testing ODE (100 boxes falling on a terrain) I get an ugly stack
> overflow. It would be better to just return an error code and not do the
> calculations than crashing. Isn't there a way to add a check for enough free
> memory beforehand? I am trying to coerce Rational Purify to provide me with
> the exact crash location, but have not been succesful yet.

I don't know offhand how to calcuate how much stack you're going to need
beforehand, but I do have two suggestions... First, increase your stack
size with the linker setting.  Windows doesn't grow the stack dynamically,
so what you set in the linker options is what you get.

Second:

	try
	{
		dWorldStep (m_WorldID, rElapsedTime);
	}
	catch (...)
	{
		// This typically results from a LARGE number of contact joints
		OutputDebugString ("Simulation failure.\n");
		fReturn = false;
	}

The "catch (...)" will catch the stack overflow, allowing you to abort the
simulation more gracefully.  Then turn up your stack size again.

Alternately, you could declare your own alloca() and write your own memory
manager.  If I understand correctly, the stack was used because its fast,
and most operating systems grow it as necessary, but it shouldn't be
rocket science to get something almost as fast using a short chain of
large heap-allocated buffers that you allocate from as if they were a
stack.


Nate Waddoups
Redmond WA USA
http://www.natew.com