From 9e8066ca9d72b82966ba066785e90fa6a2d6fab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benoi=CC=82t=20Rouleau?= Date: Sat, 10 Oct 2026 02:02:07 -0400 Subject: [PATCH] ios: pass log messages to NSLog as an argument, not as the format `NSLog` reads its first argument as a format string, and `log`, `load_file`'s "loading:" line and the panic hook all passed their message there. A message holding a format specifier made `NSLog` read arguments that were never passed: a `warn!` whose text included `%@` crashed the app with SIGSEGV, and any other `%` came out mangled. Each message now goes in as the argument to a fixed `%@` format, through `log`, so it prints as it is. Co-Authored-By: Claude Opus 5.5 --- src/native/ios.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/native/ios.rs b/src/native/ios.rs index 78ba78dd3..77879a24d 100644 --- a/src/native/ios.rs +++ b/src/native/ios.rs @@ -848,8 +848,11 @@ fn define_textfield_dlg() -> *const Class { } pub fn log(message: &str) { + // `NSLog` reads its first argument as a format string, so the message + // goes in as an argument, where a `%` in it can't be read as a specifier. + let format = apple_util::str_to_nsstring("%@"); let nsstring = apple_util::str_to_nsstring(message); - let _: () = unsafe { frameworks::NSLog(nsstring) }; + let _: () = unsafe { frameworks::NSLog(format, nsstring) }; } pub fn load_file(path: &str, on_loaded: F) { @@ -858,13 +861,12 @@ pub fn load_file(path: &str, on_loaded: F) let path_without_extension = path_without_extension.to_str().unwrap(); let extension = path.extension().unwrap_or_default().to_str().unwrap(); - unsafe { - let nsstring = apple_util::str_to_nsstring(&format!( - "loading: {} {}", - path_without_extension, extension - )); - let _: () = frameworks::NSLog(nsstring); + log(&format!( + "loading: {} {}", + path_without_extension, extension + )); + unsafe { let main_bundle: ObjcId = msg_send![class!(NSBundle), mainBundle]; let resource = apple_util::str_to_nsstring(path_without_extension); let type_ = apple_util::str_to_nsstring(extension); @@ -900,10 +902,7 @@ where { RUN_ARGS = Some((Box::new(f), conf)); - std::panic::set_hook(Box::new(|info| { - let nsstring = apple_util::str_to_nsstring(&format!("{:?}", info)); - let _: () = frameworks::NSLog(nsstring); - })); + std::panic::set_hook(Box::new(|info| log(&format!("{:?}", info)))); let argc = 1; let mut argv = b"Miniquad\0" as *const u8 as *mut i8;