Skip to content

Catch Rapier panics at FFI boundary to prevent crash#477

Open
hexadexxa wants to merge 3 commits intoryanhcode:mainfrom
hexadexxa:main
Open

Catch Rapier panics at FFI boundary to prevent crash#477
hexadexxa wants to merge 3 commits intoryanhcode:mainfrom
hexadexxa:main

Conversation

@hexadexxa
Copy link
Copy Markdown

Rapier internal assertions can panic during the physics step. Since the
JNI functions use extern "system", this unwinds across the FFI boundary
and aborts the JVM.

Wraps pipeline.step() and tick() in catch_unwind so panics are
caught and the tick is skipped instead of crashing.

… boundary

Wrap Rapier tick/step in catch_unwind to prevent JVM abort
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 24, 2026

CLA assistant check
All committers have signed the CLA.

@ryanhcode ryanhcode self-assigned this Apr 24, 2026
@hexadexxa
Copy link
Copy Markdown
Author

Should also fix issue #431 if it's the same issue

@Random-Scientist
Copy link
Copy Markdown
Contributor

Random-Scientist commented Apr 25, 2026

this is a really bad idea. the rust panics are panics for a reason; they indicate a fatal error in the physics engine (there is no mechanism for handling recoverable errors at present), ignoring these fatal errors will just invite more UB or breakages in later calls or physics steps, making everything harder to debug.

@ryanhcode
Copy link
Copy Markdown
Owner

i think it still propagates to a server crash, just through a jvm exception

@Random-Scientist
Copy link
Copy Markdown
Contributor

Random-Scientist commented Apr 25, 2026

i think it still propagates to a server crash, just through a jvm exception

At present it simply seems to ignore panics altogether (hence my comments). Clearing the physics state and raising a JVM exception with a rust backtrace would be nice but the present version of the pr just makes debugging native crashes harder.

@ryanhcode
Copy link
Copy Markdown
Owner

yeah, ignoring the panics is an absolute no-go. I'd be happy if we raised a JVM exception with the details from the panic and unrecoverably crashed the server

@hexadexxa
Copy link
Copy Markdown
Author

I see, I'll try doing that later

Catch Rapier panics at FFI boundary and throw JVM RuntimeException
@hexadexxa
Copy link
Copy Markdown
Author

Updated. Now catches the panic and throws a RuntimeException with the panic message via env.throw_new, so the server crashes with a proper crash report

Comment thread common/src/main/rust/rapier/src/lib.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants