fix(scc): catch panics at the scc_compile FFI boundary - #199
Open
ExylonDerMaster wants to merge 2 commits into
Open
fix(scc): catch panics at the scc_compile FFI boundary#199ExylonDerMaster wants to merge 2 commits into
ExylonDerMaster wants to merge 2 commits into
Conversation
Author
|
Heads up on the CI failures here (
So this looks like pre-existing toolchain drift on a branch that hasn't had CI run in a while, not a regression from this PR. Happy to help fix the unrelated clippy issue and macOS packaging step in a separate PR if that's useful. |
scc_compile is called in-process by RED4ext, directly inside the game's executable. A panic anywhere in the compiler (for example one triggered by a script that does not match the current game version) previously unwound straight across the extern C boundary into that native host, which is undefined behavior and crashed the whole game for us instead of just failing the compilation. Wrap the call in catch_unwind and turn a caught panic into a normal SccResult::Error so callers get a regular error message instead of a crash.
Two smaller fixes needed to get the panic-safety change above onto a working build: - Newer rustc misattributes a false-positive "unnecessary parentheses" lint onto the #[bitfield] fields in core/src/definition.rs and core/src/bundle.rs (the fields themselves have no parens - this is a lint bug tied to the modular_bitfield macro expansion). The workspace denies all warnings, so this otherwise breaks the build. Allow it locally in both files. - setup_logger() in scc/lib/src/lib.rs called duplicate_to_stdout(), which assumes a console is attached. scc_compile runs in-process inside the game's GUI executable, which has no console/stdout handle, so the write failed - and flexi_logger's own error-reporting path (which also goes through stdout) failed right after it, which is what actually caused flexi_logger itself to panic. That panic is what motivated the fix in the previous commit; without also removing duplicate_to_stdout here, scc_compile would still fail (now caught gracefully instead of crashing, but still failing) on every in-process invocation. File logging alone is unaffected by this and is all that's meaningful here anyway.
ExylonDerMaster
force-pushed
the
fix/scc-panic-crosses-ffi-boundary
branch
from
August 4, 2026 15:08
761e6f1 to
30f81d8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
scc_compileis invoked in-process by RED4ext, running directly inside the game's executable rather than through the standalonescc.exe. In that context a panic anywhere in the compiler — for example one triggered by a script that doesn't match the current game version — unwound straight across theextern "C"boundary into the native host. That's undefined behavior, and for us it crashed the whole game instead of just failing the compilation with an error message.This PR:
scc_compileincatch_unwindso a compiler panic becomes a normalSccResult::Errorinstead of crossing the FFI boundary.duplicate_to_stdout()fromsetup_logger()— running in-process inside a GUI executable means there's no console/stdout handle, so that write was failing, and flexi_logger's own error-reporting path (which also goes through stdout) failed right after it. That's what was actually causingflexi_loggeritself to panic on every in-process compile — the very panic that motivated fix Add a script compiler #1.#![allow(unused_parens)]incore/src/definition.rsandcore/src/bundle.rs— newer rustc misattributes a false-positive "unnecessary parentheses" lint onto the#[bitfield]-annotated fields there, and the workspace denies all warnings, so this was otherwise breaking the build.Tested by rebuilding
scc_lib.dlland confirming in-game: the flexi_logger panic is now caught and reported cleanly instead of crashing Cyberpunk 2077, and normal compile errors/successes are reported correctly via RED4ext's logs.