Greetings,
I am new to box2d and I was tossed between posting this question here or on the box2d forums. Since I am using box2d on the iphone (along with cocos2d ,of course) I thought I should ask here. Please let me know if I should ask it over at the box2d forums instead.
Anyway, I am creating a rather large world 270 by 30 (meters). Since I am using cocos 0.9 alpha, I don't specify the size of my world, but rather I use those coordinates to specify my groundBox:
b2World *world;
world = new b2World(gravity, doSleep);
world->SetContinuousPhysics(true);
// Define the ground body.
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0, 0); // bottom-left corner
groundBody = world->CreateBody(&groundBodyDef);
// Define the ground box shape.
b2PolygonShape groundBox;
float32 width=270.0f
float32 height=30.0f
// bottom edge
groundBox.SetAsEdge(b2Vec2(0,0), b2Vec2(width,0));
groundBody->CreateFixture(&groundBox);
// top edge
groundBox.SetAsEdge(b2Vec2(0,height), b2Vec2(width,height));
groundBody->CreateFixture(&groundBox);
// left edge
groundBox.SetAsEdge(b2Vec2(0,height), b2Vec2(0,0));
groundBody->CreateFixture(&groundBox);
// right edge
groundBox.SetAsEdge(b2Vec2(width,height), b2Vec2(width,0));
groundBody->CreateFixture(&groundBox);
When I run the program I get the assertion failure of:
Assertion failed: (count + 1 < k_stackSize), function Query, file libs/Box2D/Collision/b2DynamicTree.h, line 174.
So it appears that I am running into a size limitation in box2d code, I assume it is the world size as I really don't have much in this world (a smaller world seems to work fine).
Out of curiosity I looked into b2DynamicTree.h and saw that k_stacksize was set to 128. So I set it to 256 and re-compiled the box2d library. It worked with no apparent issues.
Since I am new to box2d and iphone in general I am unsure why the default value for this was 128 and what the implications might be for setting it higher. I am currently running this code on the simulator and I don't want to write something that may be unable to run on the actual iphone/itouch. But on the other hand, I would very much like to create a large world for my game.
Even assuming I don't change the value, I am concerned that a smaller world might work initially and then run into the assertion later on (when I really start adding a lot of dynamic and static objects, joints etc to the world)…so I guess I am asking if:
1) What are the implications of changing the k_stacksize in b2DynamicTree.h?
2) IS there a better way to increase the size capacity? (without needing to directly change/recompile the box2d library code)
3) If I can't/shouldn't change it, what is the maximum size of a box2d world I could safely assume to use? (I want to make sure it stays stable as I add many objects,etc to the world).
It seems strange that the new version of box2d does not require you to set the world boundaries, but at the same time have such a low size limit to the world size overall. So I assume I may be doing something wrong, or not setting some capacity somewhere?
Any help would be greatly appreciated.
Thanks,
Q
PS(One last thought.... I wanted to just clarify... the world does have a number of static sqaures in it (about 300) but only a few dynamic bodies and a few joints (less than 20 combined). Not sure if that matters but I wanted to clarify that the world is not "empty" but then again it is hardly filled to capacity.)