fix(emscripten): avoid Module.arguments access with ASSERTIONS enabled

Skip env::args() on Emscripten builds to prevent accessing Module.arguments
after runtime initialization, which causes abort with ASSERTIONS=1.
This commit is contained in:
2025-12-29 14:50:40 -06:00
parent 8d3d69da9d
commit 21078b7ada
+8 -3
View File
@@ -104,9 +104,14 @@ unsafe extern "C" fn main_loop_callback(_arg: *mut std::ffi::c_void) {
/// This function initializes SDL, the window, the game state, and then enters /// This function initializes SDL, the window, the game state, and then enters
/// the main game loop. /// the main game loop.
pub fn main() { pub fn main() {
// Parse command line arguments // Parse command line arguments (only on desktop - Emscripten ignores force_console)
let args: Vec<String> = env::args().collect(); #[cfg(not(target_os = "emscripten"))]
let force_console = args.iter().any(|arg| arg == "--console" || arg == "-c"); let force_console = {
let args: Vec<String> = env::args().collect();
args.iter().any(|arg| arg == "--console" || arg == "-c")
};
#[cfg(target_os = "emscripten")]
let force_console = false;
// On Emscripten, this connects the subscriber to the browser console // On Emscripten, this connects the subscriber to the browser console
platform::init_console(force_console).expect("Could not initialize console"); platform::init_console(force_console).expect("Could not initialize console");