Cocos2dx Box2d Step EXC_BAD_ACCESS crash

Hello There,

I am trying to debug a crash that happens in our iOS game. It does happen, if you play the game long enough. It happens when in the scheduled update, I am trying to invoke the Step method on the Box2d World instance.

Its not easy to reproduce and there are no fixed steps to reproduce it. Following is the crash report

Crashed: com.apple.main-thread
0 MyGame-mobile 0x100bfc818 void b2DynamicTree::Query(b2BroadPhase*, b2AABB const&) const + 4380690456
1 MyGame-mobile 0x100bfc2bc void b2BroadPhase::UpdatePairs(b2ContactManager*) + 4380689084
2 MyGame-mobile 0x100bf0cc4 b2World::Solve(b2TimeStep const&) + 4380642500
3 MyGame-mobile 0x100bf17d4 b2World::Step(float, int, int) + 4380645332
4 MyGame-mobile 0x1007741e4 BaseLevel::update(float) (BaseLevel.cpp:373)
5 MyGame-mobile 0x10092312c std::__1::function<void (float)>::operator()(float) const + 4377702700
6 MyGame-mobile 0x1008da8f0 cocos2d::Scheduler::update(float) + 4377405680
7 MyGame-mobile 0x10091b3f0 cocos2d::Director::drawScene() + 4377670640
8 MyGame-mobile 0x10091cc70 cocos2d::Director::mainLoop() + 4377676912
9 QuartzCore 0x1856c23c0 CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 832
10 IOKit 0x1818cb8a0 IODispatchCalloutFromCFMessage + 492
11 CoreFoundation 0x1815f0b20 __CFMachPortPerform + 188
12 CoreFoundation 0x18160bae8 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 56
13 CoreFoundation 0x18160b230 __CFRunLoopDoSource1 + 440
14 CoreFoundation 0x181608c80 __CFRunLoopRun + 2456
15 CoreFoundation 0x181528da8 CFRunLoopRunSpecific + 552
16 GraphicsServices 0x18350b020 GSEventRunModal + 100
17 UIKit 0x18b50978c UIApplicationMain + 236
18 MyGame-mobile 0x1007033b0 main (main.m:5)
19 libdyld.dylib 0x180fb9fc0 start + 4

I am not looking to get a solution here, but any ideas of when such issues might occur would immensely help.

Thanks

Deep

Do you have any idea what part of your code is involved in the crash? Can you show us?

Yea, it happens when I try to Step the Physics world.

void BaseLevel::update(float deltatime) {
getPhysicsWorld().Step(deltatime, 8, 3);
//Some more code.
}

It always seem to crash while executing the Step method. I know its not a good idea to Step the physics world with variable delta. Could that be the reason for this kind of crash?

is getPhysicsWorld() in scope?

Yes it is in scope.

Could Stepping the physics world with variable delta cause these kind of issues? Or any other ideas that could cause this problem. Forgot to mention this earlier, we are using Box2d.

I tried Stepping it with a fixed rate of 0.02 seconds, it works but it still crashes at times with a similar crash. The number of crashes are definitely lower with fixed rate stepping, but it still happens. To put things in perspective, this crash is the single biggest crash we have in the game.