stride3d / stride

Stride (formerly Xenko), a free and open-source cross-platform C# game engine.
https://stride3d.net
MIT License
6.6k stars 951 forks source link

Character component with complex collider throws exception and crashes program #1177

Open gbriggs-trmb opened 2 years ago

gbriggs-trmb commented 2 years ago

1) Starting with the Stride "Terrain" sample. 2) Added a vehicle model fbx file. 3) Used Add Physics asset / convex hull to create collider 4) Used this collider with a rigid body, works fine. 5) Tried to use this collider with a character component, and it crashes the program. 6) Made a much simpler multi box collider for the vehicle (one rectangle and four cylinders). 7) This simpler collider also crashes the program when used with a character component.

Stack trace from crash attached

strideCharacterWithComplexColliderCrash.txt

Eideren commented 2 years ago

Cast to ConvexShape on this line causing the crash https://github.com/stride3d/stride/blob/master/sources/engine/Stride.Physics/Elements/CharacterComponent.cs#L283 Here's the constructor being called on that line: https://github.com/stride3d/BulletSharpPInvoke/blob/master/BulletSharp/Dynamics/KinematicCharacterController.cs#L557

I think I remember bullet's internals not actually supporting compound shapes, that constructor definitely doesn't though. Must be verified by whoever ends up taking this over.

AmbulantRex commented 2 years ago

KinematicCharacterController requires a ConvexShape and even though the InternalShape on the CollisionShape is the base class, the actual type presented is a derived type. It is not possible to cast them between each other like we're attempting to do on https://github.com/stride3d/stride/blob/master/sources/engine/Stride.Physics/Elements/CharacterComponent.cs#L283. Bullet's sweep test also requires it to be convex internally.

We don't want to lose the reference of the internal shape so we can't just map a convex shape. Do we just alert the user more gracefully? What's the best way for them to know in advance?