kripken / box2d.js

Port of Box2D to JavaScript using Emscripten
1.32k stars 198 forks source link

Incorrect code generated in current released build (likely emscripten bug) #56

Closed mlogan closed 10 years ago

mlogan commented 10 years ago

Hi again,

I was debugging some apparently impossible behavior - basically, my contact listener was getting BeginContact called continuously while two fixtures were in contact, and then I would get only one EndContact call when the contact ceased.

Rebuilding with -profiling, I found that the first contact event came from the expected code path (b2Contact::Update), while subsequent events came from bogus code paths that made no sense.

It appears that the culprit is the -O3 in the LINK_OPTS variable in the Makefile. If I remove that, I get a working build.

Steps to reproduce:

  1. Use the current box2d.js build at https://github.com/kripken/box2d.js/blob/master/box2d.js.
  2. Run the following coffee-script: https://gist.github.com/mlogan/086c0b29ba5eafcd3af6 (javascript available at: https://gist.github.com/mlogan/04a7de8d5e3792b398ab)
  3. Observe that the begin event is triggered many times, the end event only once.
  4. Rebuild box2d.js with LINK_OPTS = (remove the -O3), rerun the reproduction script.
  5. Observe that the behavior is now correct.

Hope this is enough to go on.

mlogan commented 10 years ago

(also, the reproduction steps are for node.js, sorry for not being clear.)

mlogan commented 10 years ago

I've made the beginnings of a WebIDL-based Box2D build, and this bug does seem to be due to customizeVTable. It does not occur in optimized builds when using the WebIDL JSImplementation approach to implementing virtual methods in javascript.

kripken commented 10 years ago

Makes sense, customizeVTable was a pretty horrible hack ;)

I guess there is no point in looking into it, given that we are moving to the WebIDL version.

mlogan commented 10 years ago

Agreed.

I'm uncovering a bunch of features/bugfixes we need in webidl_binder.py, and filing PRs for them over in https://github.com/kripken/emscripten, which will all have to get merged before we can have working IDL-based bindings for box2d.js.