Skip to content

Add system that asserts physics components are finite#909

Merged
Jondolf merged 2 commits intoavianphysics:mainfrom
kristoff3r:ks/debug_finite
Dec 28, 2025
Merged

Add system that asserts physics components are finite#909
Jondolf merged 2 commits intoavianphysics:mainfrom
kristoff3r:ks/debug_finite

Conversation

@kristoff3r
Copy link
Contributor

Objective

A lot of people (me included) have had to track down NaNs or infinities that causes avian internals to crash, and they can be difficult to track down because they cause crashes a lot later than they are introduced.

Solution

Add a system when running with debug assertions that checks relevant components during PhysicsSystems::First.

For bugs in Avian internals we can potentially also schedule this system in other places.

Questions

  • I placed it in PhysicsSchedulePlugin because it feels more general purpose than the rest of PhysicsDebugPlugin and because it needs self.schedule, but I'm not sure if that's the best location for it?
  • We could make the system use assert! instead of debug_assert! and make it runnable outside of debug_assertions?

Testing

I modified one of the examples to introduce an infinity during Update and saw that it was caught.

@janhohenheim janhohenheim added C-Usability A quality-of-life improvement that makes Avian easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples A-Utils Utility functions and types S-Needs-Review Needs reviewer attention to move forward labels Dec 19, 2025
@janhohenheim janhohenheim added this to the 0.5 milestone Dec 19, 2025
@Jondolf Jondolf merged commit a383159 into avianphysics:main Dec 28, 2025
6 checks passed
Wiwip pushed a commit to Wiwip/avian that referenced this pull request Dec 29, 2025
A lot of people (me included) have had to track down NaNs or infinities that causes avian internals to crash, and they can be difficult to track down because they cause crashes a lot later than they are introduced.

Add a system when running with debug assertions that checks relevant components during `PhysicsSystems::First`.

For bugs in Avian internals we can potentially also schedule this system in other places.

* I placed it in `PhysicsSchedulePlugin` because it feels more general purpose than the rest of `PhysicsDebugPlugin` and because it needs `self.schedule`, but I'm not sure if that's the best location for it?
* We could make the system use `assert!` instead of `debug_assert!` and make it runnable outside of `debug_assertions`?

I modified one of the examples to introduce an infinity during Update and saw that it was caught.

Added mass query data accessor.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Utils Utility functions and types C-Usability A quality-of-life improvement that makes Avian easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants