# Raycast crash

**URL:** <https://forum.defold.com/t/raycast-crash/79990>\
**Category:** Questions\
**Created:** [March 7, 2025, 5:22pm UTC](https://forum.defold.com/t/raycast-crash/79990 "2025-03-07T17:22:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [March 7, 2025, 5:22pm UTC](https://forum.defold.com/t/raycast-crash/79990/1 "2025-03-07T17:22:59Z")

</div>

I bumped into a crash when using raycasts under certain conditions:

This code:

```lua
	local from = vmath.vector3(0, -13200000, 0)
	local to = from + vmath.vector3(0, -1, 0)
	local groups = {hash("test")}
	physics.raycast(from, to, groups)

```

Together with the game.project setting:

```lua
[physics]
scale = 0.01

```

Causes a crash with this message:

`Assertion failed: (r.LengthSquared() > 0.0f), function RayCast, file b2DynamicTree.h, line 232.`

Usually when a ray’s vector has 0 length, this warning is displayed instead:

`WARNING:PHYSICS: Ray had 0 length when ray casting, ignoring request.`

It could have something to do with floating point precision, because of the extreme numbers, coupled with a short ray.

The crash can be avoided, but it may be better to catch it and display the above message instead? I can add a Github issue for this if needed.

Defold 1.9.7. Minimal repro:  
[RaycastCrash.zip](https://forum.defold.com/uploads/short-url/fIRdrveJOZt2kn2Y1Zce2kQXkf9.zip) (3.6 KB)

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [March 8, 2025, 8:32am UTC](https://forum.defold.com/t/raycast-crash/79990/2 "2025-03-08T08:32:03Z")

</div>

Thanks. Please report on Github so we don’t forget about it.

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [March 8, 2025, 2:42pm UTC](https://forum.defold.com/t/raycast-crash/79990/3 "2025-03-08T14:42:21Z")

</div>

Done!

[https://github.com/defold/defold/issues/10312](https://github.com/defold/defold/issues/10312)
