Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test bed #110

Merged
merged 3 commits into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions demo/html5canvas/testbed.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<script type="text/javascript">
var Box2D;
if (!Box2D) Box2D = (typeof Box2D !== 'undefined' ? Box2D : null) || Module;
var Box2DConstructor = Box2D
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this is never used?

Box2D = Box2D()
huy-nguyen marked this conversation as resolved.
Show resolved Hide resolved
Module = Box2D
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also doesn't look used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed line 24 (Box2DConstructor) but if I remove the other 2 lines, I get this error message:

Uncaught TypeError: Box2D.JSDraw is not a constructor
    at getCanvasDebugDraw (embox2d-html5canvas-debugDraw.js:85)
    at init (embox2d-html5canvas-testbed.js:275)
    at window.onload (testbed.html:27)

I think those 2 lines are essential to the working of the test bed.

window.onload = function() {
using(Box2D, "b2.+")
init();
Expand Down
12 changes: 6 additions & 6 deletions helpers/embox2d-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ function scaledVec2(vec, scale) {
// http://stackoverflow.com/questions/12792486/emscripten-bindings-how-to-create-an-accessible-c-c-array-from-javascript
function createChainShape(vertices, closedLoop) {
var shape = new Box2D.b2ChainShape();
var buffer = Box2D.allocate(vertices.length * 8, 'float', Box2D.ALLOC_STACK);
var buffer = Box2D._malloc(vertices.length * 8);
var offset = 0;
for (var i=0;i<vertices.length;i++) {
Box2D.setValue(buffer+(offset), vertices[i].get_x(), 'float'); // x
Box2D.setValue(buffer+(offset+4), vertices[i].get_y(), 'float'); // y
Box2D.HEAPF32[buffer + offset >> 2] = vertices[i].get_x();
Box2D.HEAPF32[buffer + (offset + 4) >> 2] = vertices[i].get_y();
offset += 8;
}
var ptr_wrapped = Box2D.wrapPointer(buffer, Box2D.b2Vec2);
Expand All @@ -59,11 +59,11 @@ function createChainShape(vertices, closedLoop) {

function createPolygonShape(vertices) {
var shape = new Box2D.b2PolygonShape();
var buffer = Box2D.allocate(vertices.length * 8, 'float', Box2D.ALLOC_STACK);
var buffer = Box2D._malloc(vertices.length * 8);
var offset = 0;
for (var i=0;i<vertices.length;i++) {
Box2D.setValue(buffer+(offset), vertices[i].get_x(), 'float'); // x
Box2D.setValue(buffer+(offset+4), vertices[i].get_y(), 'float'); // y
Box2D.HEAPF32[buffer + offset >> 2] = vertices[i].get_x();
Box2D.HEAPF32[buffer + (offset + 4) >> 2] = vertices[i].get_y();
offset += 8;
huy-nguyen marked this conversation as resolved.
Show resolved Hide resolved
}
var ptr_wrapped = Box2D.wrapPointer(buffer, Box2D.b2Vec2);
Expand Down