kripken / box2d.js

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

Re-building on mac os makes testbed fail #14

Open kjyv opened 11 years ago

kjyv commented 11 years ago

I tried to rebuild box2d.js in order to see more useful error messages while trying to port an application from box2dweb and to actually be able to read the code that I'm using. I'm on OSX. After installing llvm and clang 3.1 (with macports), I changed the llvm path in the makefile and removed the -O2 parameter (later, I also tried building with the original parameter set). I also set -xc++ as the comment suggested. Now, running make results in a new box2d.js file, which I copied into html5canvas_demo as embox2d.js, which results in a very long error message that starts with Uncaught TypeError: Property '0' of object 0,0,function __ZN15b2ContactFilterD1Ev($this) {

(lots of function calls in libcxx in between) and ends in },0 is not a function. This is on chrome 24. I get a similar output in Firefox. Going back to 23b2a7903505c69f0252fa891c8fc7cac08a58bc of emscripten yields the same behaviour.

Using the box2d.js from git, it runs fine. What is wrong?

kripken commented 11 years ago

Not sure, we'd need to debug it. First though, can you test on linux?

kjyv commented 11 years ago

Yes, I can try. And yes, it seems to be alright there. I built with llvm 3.1 and clang 3.0 on ubuntu and while comparing versions I found that the default clang points to the 3.0svn based clang version that apple supplied. After that I tried clang 3.0 from macports but it still results in the same problem. The same with llvm-3.0 + clang-3.0

kripken commented 11 years ago

Might be worth trying to build llvm+clang 3.1 and testing with that - we've had reports of problems with modified versions in repos.

On Wed, Nov 28, 2012 at 7:50 PM, Stefan notifications@github.com wrote:

Yes, I can try. And yes, it seems to be alright there. I built with llvm 3.1 and clang 3.0 on ubuntu and while comparing versions I found that the default clang points to the 3.0svn based clang version that apple supplied. After that I tried clang 3.0 from macports but it still results in the same problem.

— Reply to this email directly or view it on GitHubhttps://github.com/kripken/box2d.js/issues/14#issuecomment-10834123.

kjyv commented 11 years ago

I just tried that, same issue. Just at the end of making, I get this

Warning: Unresolved symbol: ZSt9terminatev Warning: Unresolved symbol: _llvm_va_start Warning: Unresolved symbol: ZNK12b2WheelJoint13GetDefinitionEP15b2WheelJointDef Warning: Unresolved symbol: ZNSt9type_infoD2Ev Warning: Unresolved symbol: _llvm_dbg_declare Warning: Unresolved symbol: _llvm_expect_i32 Warning: Unresolved symbol: ZNSt9exceptionD2Ev

in between, there are also a few warnings "(...) C-linkage specified, but returns user-defined type 'b2Vec2 &' which is incompatible with C [-Wreturn-type-c-linkage]"

Is it possible that some wrong c libraries are used?

kripken commented 11 years ago

Can you gist the entire build output? Something is definitely not going right if that is the output.

kjyv commented 11 years ago

Sure, here you go. https://gist.github.com/4205181 (make output and errors are separated)

kripken commented 11 years ago

That output is actually correct.

Try on latest emscripten and llvm 3.2, if that doesn't work, please run with EMCC_DEBUG=1 and paste the output and files.

bunnyhero commented 11 years ago

I am also getting runtime errors with box2d.js when building it on my Mac. I am using the binary release of LLVM 3.2 (clang+llvm-3.2-x86_64-apple-darwin11 as specified in this gist https://gist.github.com/dweekly/5873953 ). The build completes without error, but running the testbed results in an "Assertion: 20" error. If I build a non-optiimized version of box2d.js, I get the following error:

Uncaught TypeError: Property '0' of object [object Array] is not a function embox2d.js:24323
__ZN9b2Fixture6CreateEP16b2BlockAllocatorP6b2BodyPK12b2FixtureDef embox2d.js:24323
__ZN6b2Body13CreateFixtureEPK12b2FixtureDef embox2d.js:20131
__ZN6b2Body13CreateFixtureEPK7b2Shapef embox2d.js:19812
_emscripten_bind_b2Body__CreateFixture_p2 embox2d.js:61984
b2Body.CreateFixture embox2d.js:80137
embox2dTest_dominos.setup dominos.js:19
createWorld embox2d-html5canvas-testbed.js:314
resetScene embox2d-html5canvas-testbed.js:318
changeTest embox2d-html5canvas-testbed.js:292
window.onload testbed.html:25

Here is the build output, with EMCC_DEBUG=1: https://gist.github.com/bunnyhero/5915887

I have also confirmed that box2d.js builds correctly on Linux with the same sources for emscripten and box2d.js.

Let me know if there are any other files I should share. Thank you.

Update: I compared the box2d.bc files generated on Mac and on Linux. While they are identical in size, their contents differ. I could upload the LLVM disassemblies of each somewhere if that would help (they're about 3.5 MB each uncompressed).

bunnyhero commented 11 years ago

I don't know if this is a valid thing to do, but: because I noticed that all of the generated .bc files were the same on Mac and Linux (except for box2d_bindings.bc), I copied box2d.bc from Linux to the Mac, and ran emmake make again (so that it would only run the last step of the Makefile). The resulting box2d.js file exhibits the runtime error noted above.

This might suggest that the error is occurring in the final conversion to JavaScript.

bunnyhero commented 11 years ago

More investigation:

I used the same Linux-generated box2d.bc on Mac and on Linux, and ran

../emscripten/emcc --clear-cache
rm -f /tmp/emscripten_temp/*
EMCC_DEBUG=1 EMCC_CORES=1 ../emscripten/emmake make

on both platforms, and then investigated the cache files and temp files.

The cache files (for libc etc) were identical. The temp files, however:

Linux:

    $ openssl dgst -sha1 /tmp/emscripten_temp/*
    SHA1(/tmp/emscripten_temp/emcc-0-basebc.bc)= f4fe5cfa75591540b75c357507a134232541d2d9
    SHA1(/tmp/emscripten_temp/emcc-1-linktime.bc)= 1894450c508ac3ab320bb436a09e92c86e839c5c
    SHA1(/tmp/emscripten_temp/emcc-2-ll.ll)= debb808c3ff9fb3a96a95b368acab22f00a7aa87
    SHA1(/tmp/emscripten_temp/emcc-3-original.js)= d402c09e8859aa4dbea389ae3f3ef2aa416b1ffa
    SHA1(/tmp/emscripten_temp/emcc-4-transformed.js)= 7ec6c64bad9413dd23306474b928cc542032b20a

Mac:

    $ openssl dgst -sha1 /tmp/emscripten_temp/*
    SHA1(/tmp/emscripten_temp/emcc-0-basebc.bc)= f4fe5cfa75591540b75c357507a134232541d2d9
    SHA1(/tmp/emscripten_temp/emcc-1-linktime.bc)= 1894450c508ac3ab320bb436a09e92c86e839c5c
    SHA1(/tmp/emscripten_temp/emcc-2-ll.ll)= eed3eee8e7e40c8939683091093d49d8215d0b0c
    SHA1(/tmp/emscripten_temp/emcc-3-original.js)= d402c09e8859aa4dbea389ae3f3ef2aa416b1ffa
    SHA1(/tmp/emscripten_temp/emcc-4-transformed.js)= 194d9a4c6319c6a575b86193b4921a9fcba6f73b

Not sure if this is helpful for figuring out where I should look next; apologies for all the comments.

UPDATE: the difference in the .ll file seems insignificant, it was just this:

1c1
< ; ModuleID = '/tmp/tmpqZFIEO/box2d.bc'
---
> ; ModuleID = '/tmp/tmpiKBeDd/box2d.bc'

so I think somewhere between original.js and transformed.js, something goes wrong on the Mac.

bunnyhero commented 11 years ago

Last comment before I see if I can fix or work around this: the problem seems to be with the C preprocessor on the Mac. The box2d.clean.h file it generates results in a broken bindings file. If I use the Linux-generated box2d.clean.h, then the bindings file gets created fine. Note that on recent versions of Xcode, the cpp command is actually a shell script that wraps llvm-gcc-4.2 -E.

Apologies for all the noise...