kripken / box2d.js

Port of Box2D to JavaScript using Emscripten
1.33k stars 196 forks source link

local build: circle shapes not visible in testbed #50

Open jarbot opened 10 years ago

jarbot commented 10 years ago

Built box2d.js with 1.16 emscripten fastcomp

Circle shapes are effected by physics and I can see the axes but the fill and stroke are not visible. All other shapes look fine.

Here's the out from the build process: https://gist.github.com/jarbot/b7ef2241d46cfc686731

kripken commented 10 years ago

How does it render? If it's using GL emulation, could be a limitation of that. Otherwise, it should work, please make as reduced a testcase as you can.

jarbot commented 10 years ago

I'm testing with the canvas testbed https://github.com/kripken/box2d.js/blob/master/html5canvas_demo/tests/fallingShapes.js

b2CircleShape(); <- doesn't seem to render the fill or stroke but is still affected by physics simulation

kripken commented 10 years ago

I think @iforce2d wrote that, iforce2d?

iforce2d commented 10 years ago

Yes. I just did a git clone and it looks ok when running with the box2d.js as in the repo... @jarbot when you say 'axes' you mean the red and green marker for the body position right? Is the drawCircle function in embox2d-html5canvas-debugDraw.js being entered at all?

jarbot commented 10 years ago

The box2d.js from the repo works fine for me too. It's when I do my own build that the circle doesn't render.

when you say 'axes' you mean the red and green marker for the body position right? Correct.

I set a break point on line 50 of embox2d-html5canvas-debugDraw.js and it never gets hit.

iforce2d commented 10 years ago

@jarbot After building with the latest source I was able to reproduce the problem you describe.

It looks like customizeVTable is not matching the correct function when replacing the virtual functions of b2Draw. Instead of matching DrawCircle, it is matching DrawTransform, so you see an axis marker instead of a circle. As the comments for customizeVTable indicate, the method used to replace virtual functions may not be 100% reliable:

  // Prepare replacement lookup table and add replacements.
  // There is actually no good way to do this! So we do the following hack:
  // We create a fake vtable with canary functions, to detect which actual
  // function is being called

Unfortunately I have no idea why the problem occurs or how to fix it, but I found two ways to avoid it. The first is to remove the -O2 flag from the final step in the makefile, if you can live with a slightly larger/slower build.

The other way is to move the call to customizeVTable for the two circle drawing functions (DrawCircle and DrawSolidCircle) so that they appear after that of DrawTransform (these calls are in embox2d-html5canvas-debugDraw.js). Obviously this is not ideal, because then the transform marker axes do not get drawn... just thought I would mention it anyway.

jarbot commented 10 years ago

@iforce2d thank you for spending the time to look into this. I will give the -O2 approach a shot and hope it doesn't get too slow.