Box2D collisions cause crash on all but Flash targets

In particular, I receive an EXC_BAD_ACCESS on iOS (simulator and device). Appears to be happening in B2WorldManifold initialize, but I've been unable to determine why. #0 0x003d3e59 in box2D::collision::B2WorldManifold_obj::initialize(hx::ObjectPtr, hx…

  • Forums
  • »
  • Bugs
  • »
  • Box2D collisions cause crash on all but Flash targets
Viewing 1 to 10 (10 Total)
Box2D collisions cause crash on all but Flash targets

magnate

magnate
Total Posts: 15
Joined: November 15, 2011

In particular, I receive an EXC_BAD_ACCESS on iOS (simulator and device). Appears to be happening in B2WorldManifold initialize, but I've been unable to determine why.

#0 0x003d3e59 in box2D::collision::B2WorldManifold_obj::initialize(hx::ObjectPtr, hx::ObjectPtr, double, hx::ObjectPtr, double) ()

I'm using output from PhysicsEditor to create my Box2D fixtures and polys, and those are drawing correctly using Box2D's debug draw mode. The crash occurs exactly on the first collision.

Tags:
Posted on November 19, 2011 at 9:42 PM

singmajesty

singmajesty
Total Posts: 2141
Joined: August 25, 2011

Re: Box2D collisions cause crash on all but Flash targets

Which port of Box2D are you using?

Do you get the same crash if you target "mac" instead of "ios"?

Thanks!

Posted on November 19, 2011 at 9:55 PM

magnate

magnate
Total Posts: 15
Joined: November 15, 2011

Re: Re: Box2D collisions cause crash on all but Flash targets

I've tried using both the haxelib and SVN versions of your box2dhaxelib port, and yeah, compiled for iOS, Mac, Android, and of those only Flash is working correctly. I'm not sure if it's because the AVM is much less strict or what.

I think I've tracked to where I think the crash is originating, at least generally. Somewhere in B2WorldManifold, or B2PositionSolverManifold, or B2ContactSolver. Investigations continue!

Posted on November 19, 2011 at 10:48 PM

magnate

magnate
Total Posts: 15
Joined: November 15, 2011

Re: Box2D collisions cause crash on all but Flash targets

Josh - it turned out to be related to the B2Settings class and its "static public" vars. I modified them all to be "public static inline" vars and now collisions work correctly. Strange!

Posted on November 20, 2011 at 8:11 AM

singmajesty

singmajesty
Total Posts: 2141
Joined: August 25, 2011

Re: Box2D collisions cause crash on all but Flash targets

Hah! Weird!

Have you confirmed that this fixes it for all targets?

If you can attach a diff real quick, that would be nice, or the updated B2Settings.hx file, it might speed things up on my end. If this really fixes it, then I'll try and get this integrated and update haxelib as soon as I can. Thanks for digging into this!

Posted on November 20, 2011 at 10:16 AM

wedders

wedders
Total Posts: 12
Joined: October 08, 2011

Re: Box2D collisions cause crash on all but Flash targets

Just to confirm: I had the exact same problem, using the source in my project so I could do a few modifications, and randomly one day it started crashing on any collision. I debugged a CPP build and found the error to be occuring in one line in B2WorldManifold every time (I forget which now, I did this a while ago), and I tried a load of stuff to get it working again...

Just remembered reading this and thought I'd try it and it's worked beautifully (on webOS, at least), just replace all "static public var" => "pubic static inline var".

Posted on January 18, 2012 at 12:29 PM

Huge

Huge
Total Posts: 548
Joined: October 07, 2011

Re: Box2D collisions cause crash on all but Flash targets

Hi,
This has jsut been discussed on the haxelang google group.
The easiest fix seems to be a dummy variable to help the compiler get the construction order right.

Hugh

Posted on January 18, 2012 at 7:18 PM

magnate

magnate
Total Posts: 15
Joined: November 15, 2011

Re: Box2D collisions cause crash on all but Flash targets

Hugh - I'm not certain what you mean by using a dummy variable for the compiler?

Posted on January 19, 2012 at 4:48 PM

Zaphod

Zaphod
Total Posts: 218
Joined: September 15, 2011

Re: Box2D collisions cause crash on all but Flash targets

@magnate add this:

private static var dummy = B2Settings.b2_maxManifoldPoints;

to the B2ContactSolver class makes the compiler generates correct static initialization.

A good fix until it is solved in hxcpp.

Posted on January 20, 2012 at 3:28 AM

singmajesty

singmajesty
Total Posts: 2141
Joined: August 25, 2011

Re: Box2D collisions cause crash on all but Flash targets

I have committed a new version of the "box2d" library on haxelib. Feel free to upgrade ("haxelib upgrade box2d") and see if it makes a difference.

Posted on January 21, 2012 at 12:10 PM