jrouwe / JoltPhysics.js

Port of JoltPhysics to JavaScript using emscripten
MIT License
270 stars 21 forks source link

Memory Bounds Error when trying to create HeightField #125

Closed DennisSmolek closed 7 months ago

DennisSmolek commented 7 months ago

I'm trying to create a heightfield in a class using the official example as a reference.

For some reason though I'm getting a Memory access out of bounds Error: image

I created a super simple version with no field creation and it's still throwing the error:

public addHeightfield() {
        const position = new Jolt.Vec3(0, -20, 0); // The image tends towards 'white', so offset it down closer to zero
        const quaternion = new Jolt.Quat(0, 0, 0, 1);
        const shapeSettings = new Jolt.HeightFieldShapeSettings();
        const shape = shapeSettings.Create().Get();

        const creationSettings = new Jolt.BodyCreationSettings(
            shape,
            position,
            quaternion,
            Jolt.EMotionType_Static,
            Layer.NON_MOVING,
        );
        const body = this.bodyInterface.CreateBody(creationSettings);
        Jolt.destroy(shapeSettings);
        return body;
    }

It only fires on the const body = this.bodyInterface.CreateBody(creationSettings); line. However, if I replace the shape with a simple BoxShape I get no errors.

I can't see anything obvious.. My quick guess is that I'm missing something required for the heightfield and something is/should be throwing inside jolt and this memory error is just what I can see in js land.

I'm on jolt-physics 0.19 and the WASM embedded with import Jolt from 'jolt-physics';

DennisSmolek commented 7 months ago

Figured it out. Was missing: shapeSettings.mSampleCount which apparently is required