dimforge / rapier.js

Official JavaScript bindings for the Rapier physics engine.
https://rapier.rs
Apache License 2.0
430 stars 58 forks source link

"RuntimeError: unreachable" error with heightfields #47

Open gabrielbrunop opened 3 years ago

gabrielbrunop commented 3 years ago

I'm trying to create a 2D heightfield but it throws a unreachable error at runtime for no apparent reason.

image

...

const rigidBody = this.world.createRigidBody(rigidBodyDesc);
const colliderDesc = RAPIER.ColliderDesc.heightfield(new Float32Array([ 2, 3 ]), { x: 50.0, y: 1.0 });
const collider = this.world.createCollider(colliderDesc, rigidBody.handle);

...

Also, on the testbed heightfield.js example it passes an array to the heights parameters, but on Typescript it requires a Float32Array. Anyway, the testbed example also doesn't work:

let ground_size = {x: 50.0, y: 1.0};
let nsubdivs = 100;
let heights = [];

heights.push(40.0);

for (let i = 1; i < nsubdivs; ++i) {
    heights.push(Math.cos(i * ground_size.x / (nsubdivs)) * 2.0);
}

heights.push(40.0);

...

const colliderDesc = RAPIER.ColliderDesc.heightfield(new Float32Array(heights), ground_size);
const collider = this.world.createCollider(colliderDesc, rigidBody.handle);

...

I'm using the latest version of Rapier2D (0.7.6).

gabrielbrunop commented 3 years ago

I think I found the problem.

The coordinates of the heightfield were in the same spot as another polyline. And that polyline was created as a dynamic body. I thought it doesn't matter but it seems that if a dynamic polyline or heightfield intersects with a static body, it crashes.

Although making it static will work just fine for me, I guess that's not intended behaviour?

khudiiash commented 4 months ago

I have the same problem, even though the heightfield is fixed and it does not intersect with anything. No matter what params I feed into the heightfield, it crashes. The only difference from the official example is that it runs in a worker, but I don't see any reason why it shouldn't work in a worker.