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

"unreachable" error when using heightmap #22

Open
viridia opened this issue Apr 22, 2021 · 3 comments
Open

"unreachable" error when using heightmap #22

viridia opened this issue Apr 22, 2021 · 3 comments

Comments

@viridia
Copy link
Contributor

viridia commented Apr 22, 2021

I'm getting the following error:

Uncaught RuntimeError: unreachable
    at std::panicking::rust_panic_with_hook::h9d91fa0fae16500f (http://localhost:3000/0c0ef481b8428110185b.module.wasm:wasm-function[788]:0x108529)
    at std::panicking::begin_panic_handler::{{closure}}::h2d82b5b2db976f3f (http://localhost:3000/0c0ef481b8428110185b.module.wasm:wasm-function[897]:0x10d32a)
    at std::sys_common::backtrace::__rust_end_short_backtrace::h24539600b7e2452c (http://localhost:3000/0c0ef481b8428110185b.module.wasm:wasm-function[1245]:0x114d35)
    at rust_begin_unwind (http://localhost:3000/0c0ef481b8428110185b.module.wasm:wasm-function[1161]:0x113c87)
    at core::panicking::panic_fmt::h91d2023e5afe1929 (http://localhost:3000/0c0ef481b8428110185b.module.wasm:wasm-function[1247]:0x114d99)
    at core::panicking::panic::h5da66f104e83c46a (http://localhost:3000/0c0ef481b8428110185b.module.wasm:wasm-function[1111]:0x112e78)
    at rapier3d::geometry::broad_phase_multi_sap::sap_axis::SAPAxis::batch_insert::h22440a950023a6c1 (http://localhost:3000/0c0ef481b8428110185b.module.wasm:wasm-function[58]:0x6e464)
    at rapier3d::geometry::broad_phase_multi_sap::broad_phase::BroadPhase::update::hcb9a53f41ef84931 (http://localhost:3000/0c0ef481b8428110185b.module.wasm:wasm-function[46]:0x5b78c)
    at rapier3d::pipeline::physics_pipeline::PhysicsPipeline::detect_collisions::he6a99ba9c9b1190f (http://localhost:3000/0c0ef481b8428110185b.module.wasm:wasm-function[321]:0xdbb17)
    at rapier3d::pipeline::physics_pipeline::PhysicsPipeline::step::h0bcdada6b45b091e (http://localhost:3000/0c0ef481b8428110185b.module.wasm:wasm-function[45]:0x59992)

What is interesting is that if I fill the heightmap with all zeroes, I don't get this error. If I pass in real terrain data I do.

Even more strangely, if I multiply the data by a small constant (.01) the error goes away, but I multiply by (.99) it happens. So basically it is as if the magnitude of what is in the array matters. I've tried a bunch of other combinations, it's completely consistent but I can't figure out the pattern.

Note: it took me a few hours to even get this stack dump, as I had to build the library locally in order to turn on debug symbols, and I had to fuss with it to get it to build on my system.

The way I am building the height map isn't very interesting either:

/** Physics object representing a height field such as terrain. */
export class PhysicsHeightField {
  #body: RigidBody;
  #collider: Collider | null = null;

  constructor(private rapier3d: R, private world: World, position: Vector2) {
    // TODO: Add friction and such.
    const rbDesc = rapier3d.RigidBodyDesc.newDynamic().setTranslation(position.x, 0, position.y);
    this.#body = this.world.createRigidBody(rbDesc);
  }

  public dispose() {
    if (this.#collider) {
      this.world.removeCollider(this.#collider);
      this.#collider = null;
    }
    this.world.removeRigidBody(this.#body);
  }

  public setHeights(heights: Float32Array) {
    // Remove previous collider, if any.
    if (this.#collider) {
      this.world.removeCollider(this.#collider);
    }
    // Generate new height map from data.
    const clDesc = this.rapier3d.ColliderDesc.heightfield(
      PLOT_LENGTH,
      PLOT_LENGTH,
      heights,
      terrainScale
    );
    this.#collider = this.world.createCollider(clDesc, this.#body.handle);
  }
}
@viridia
Copy link
Contributor Author

viridia commented Apr 22, 2021

So changing it to static made the problem go away - still don't know why.

I'm finding it very difficult to debug problems, such as when I pass in a bad param - it just throws "unreachable" with no explanatory message as to what went wrong.

@aunyks
Copy link

aunyks commented Aug 22, 2021

Thanks for following up with how you've solved this. I'm running into the same error with the Heightfield but making it Static hasn't worked yet. I'll follow up if I find a solution, for others who are running into this.

@sebcrozet
Copy link
Member

@aunyks Are you using the latest version of Rapier? This issue may be related to a bug that has been fixed recently. If you are using the latest version, could you please provide a piece of code to reproduce it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants