amerkoleci / JoltPhysicsSharp

JoltPhysics C# bindings
MIT License
238 stars 34 forks source link

Crash with HeightFieldShape #90

Closed galvesribeiro closed 1 month ago

galvesribeiro commented 1 month ago

Hello!

At our initial test I was trying to create a HeightFieldShape to represent our terrain but after initialize the PhysicsSystem and start creating the objects the process just crash. No logs, no errors, just exit.

The sample core to reproduce after the PhysicsSystem initialization is like this:

 int width = 513;
            int length = 513;
            Vector3 positionTest = new Vector3(-25.5f, 0.099f, -25.1f);
            var samples = new float[width * length];
            var heightFieldSettings = new HeightFieldShapeSettings(samples, positionTest, new Vector3(100f, 1f, 100f));

            var heightFieldShape = new HeightFieldShape(heightFieldSettings);
            var settingsTest = new BodyCreationSettings(heightFieldShape, positionTest, Quaternion.Identity, MotionType.Static,
                Layers.NonMoving);

The code actually crashes with this call on the constructor which calls JPH_HeightFieldShapeSettings_Create:

image

Any idea what that may be?

Thanks!

amerkoleci commented 1 month ago

Hi, There was an issue in the native call, please update to 2.9.2 and it should be fixed.

Thanks

galvesribeiro commented 1 month ago

Thanks for the quick update.

I've updated to 2.9.2 but the same problem still happen.

It crashes immediately when run that line:

image
amerkoleci commented 1 month ago

You need to pass the width as sampleCount not samples.Length

galvesribeiro commented 1 month ago

Good catch. It worked.

Is that kind of error/crashes reported anywhere? I've set both the TraceHandler and the AssertFailure handlers but they weren't never triggered.

Thanks!

amerkoleci commented 1 month ago

It crashed on jolt side: https://github.com/jrouwe/JoltPhysics/blob/master/Jolt/Physics/Collision/Shape/HeightFieldShape.cpp#L89

So jump there and ask the author to improve the error maybe?

galvesribeiro commented 1 month ago

Cool thanks!