I need to make a custom manual traversal of DB. I took as starting point the example below code given in the User Guide Vol 1 page 40. When running the code it crashes due to stack overflow when the counter shows 63000. Nevertheless when traversing the DB using the walk API function then no problem.
Where is the problem?
Thanks in advance.
void SimpleTraverse (mgrec *node)
// traverse a simple database with no instances, external references, or subfaces
counterTest++; // it is static global counter
if( counterTest % 1000 == 0)
printf ("%d\n", counterTest);
// traverse down
if (mgGetChild (node))
SimpleTraverse (mgGetChild (node));
// traverse right
if (mgGetNext (node))
SimpleTraverse (mgGetNext (node));
This problem is most likely related to the Stack Size of your application. When you build your application (in Visual Studio, for example), you set the maximum stack size as a linker option. This is the maximum size your program stack is allowed to grow during program execution. The stack grows when you use recursion as your program is doing. If you don't set this explicitly, you get defaults from your build environment (Visual Studio gives you 1MB typically by default).
You do this with the /STACK linker option. Try setting it to:
This is happening (most likely) as you recurse to process the next node. The mgWalk function does not recurse to visit next nodes, it uses looping - for this very reason. That would explain why your function overflows and mgWalk does not.
If you are using OpenFlight API 4.2, there is a FAQ on this very subject in the OpenFlight API Reference.
Thanks for the prompt reply!