[solved] SphereCast crash

The game is access-violating me in both: delphi and fpc compilations, whenever I call the PhysicalSphereCast, when I have no colliders on any object. (pic 1)

The test environment is basically the Empty Template with few basic transforms sitting on the ground. I added to the (GameViewMain.pas) Press(...) the following:

var
  RayCastResult: TRayCastResult;
begin
...
  if Event.IsMouseButton(buttonLeft) then
  begin
   RayCastResult := Viewport1.Items.PhysicsSphereCast( Camera1.Position, 0.1, Camera1.Direction);

Optionally I have added distance limit to see if the error persists, but it’s still crashing.

Adding just a single, basic TCastleBoxCollider to one of the boxes (pic 2), or to any transform, was enough to stop the game from crashing, so I guess it was happening because of zero instances of physic colliders in the world.


Fixed, thank you!

( Background: physics engine is initialized on-demand, so when there was no TCastleRigidBody – it wasn’t initialized. But you should not ever need to know this – it’s an internal detail when do we initialize physics engine, and it can change in the future. So of course we should just return hit:=false (since it’s not possible to hit anything in this case). Done in Fix Viewport.Items.PhysicsRay/SphereCast in case world has no TCastle… · castle-engine/castle-engine@d2f6ebc · GitHub )