ndk
ndk copied to clipboard
Cannot initialize sdl2 from the main function
I'm facing the following issue,
When I try to initialize sdl2 from my main function, the project compiles without errors. But when I run it, I can see that it fails in the sdl2 init call.
lib.rs
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))]
fn main() {
println!("Hello from Android!");
let _ = sdl2::init().unwrap();
}
These are the entries that I'm seeing in logcat:
02-08 04:06:55.196 14840 14884 I RustStdoutStderr: Hello from Android!
02-08 04:06:55.196 14840 14884 I RustStdoutStderr: thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: "Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?"', src/lib.rs:17:36
02-08 04:06:55.196 14840 14884 I RustStdoutStderr: stack backtrace:
02-08 04:06:55.202 14840 14884 I RustStdoutStderr: note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Please let me know if you need additional details. Thanks
Just vague recollections of using SDL2, but the C API used to do some funky things with redefining main
to SDL_Main
or something like that - I wonder if the Android backed for SDL2 requires you to jump through some special main function wrapper they have?
Forgive me for asking though; is the sdl2 crate a sys wrapper around the SDL2 C library? If so I can't help but guess you might be unintentionally adding quite a bit more complexity to the system than by setting up the SDL main loop via a C main function using the original android_native_app_glue.c
that comes with the NDK - but just a thought without any context.