box2d.js icon indicating copy to clipboard operation
box2d.js copied to clipboard

local build: circle shapes not visible in testbed

Open jarbot opened this issue 10 years ago • 7 comments

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

jarbot avatar Jun 18 '14 23:06 jarbot

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.

kripken avatar Jun 19 '14 18:06 kripken

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

jarbot avatar Jun 19 '14 18:06 jarbot

I think @iforce2d wrote that, iforce2d?

kripken avatar Jun 19 '14 18:06 kripken

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?

iforce2d avatar Jun 19 '14 18:06 iforce2d

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.

jarbot avatar Jun 19 '14 19:06 jarbot

@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.

iforce2d avatar Jun 20 '14 04:06 iforce2d

@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.

jarbot avatar Jun 20 '14 06:06 jarbot