Skip to content

Commit

Permalink
Fix test bed (#110)
Browse files Browse the repository at this point in the history
Adapt the solution from #87 (comment) and fix script loading error to make the test bed work again.

Fixes #97.
  • Loading branch information
huy-nguyen authored Jun 1, 2020
1 parent a889080 commit f75077b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions demo/html5canvas/testbed.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<script type="text/javascript">
var Box2D;
if (!Box2D) Box2D = (typeof Box2D !== 'undefined' ? Box2D : null) || Module;
Box2D = Box2D();
Module = Box2D;
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;
}
var ptr_wrapped = Box2D.wrapPointer(buffer, Box2D.b2Vec2);
Expand Down

0 comments on commit f75077b

Please sign in to comment.