android-rs-glue
android-rs-glue copied to clipboard
Opening an app twice results in a crash
Steps to reproduce:
- Create
fn main() { loop {} }
app - Open the app
- Hit the back arrow
- Open the app again
Output: Is slightly mangled (not sure why, probably another bug), but basically
assertion failed: (*ptr).is_none(): src/libstd/sys/common/args.rs:63
Cause:
The glue code calls the main
symbol, not the fn main
in the app. The main symbol runs the start
lang item, which by default is this. Some of the code called by that should only be called once per process (in particular the line we die at). Android starts new activities of an app that has already been opened in the same process.
The android_main function is supposed to detect that and not run the app a second time.
Hmm... it's obviously not succeeding, I'll try and figure out why.
Is it a good idea to be running the normal runtime code on Android in the first place though? It feels like doing a lot of process management that Android prefers to do itself.
With this line being commented out, g_mainthread_boxed
never becomes Some(_)
, so is_app_thread_terminated
always returns as if it was a new process.
That line was commented out in this comment, I'm not sure why?
The real code won't work if you don't call the normal runtime code. For example that's why the glue uses raw pthreads instead of Rust threads before initializing the runtime.
With this line being commented out, g_mainthread_boxed never becomes Some(_), so is_app_thread_terminated always returns as if it was a new process.
That line was commented out in this comment, I'm not sure why?
Oh, that's probably a mistake.
The real code won't work if you don't call the normal runtime code. For example that's why the glue uses raw pthreads instead of Rust threads.
Doesn't the runtime just initialize stack guards, oom_handler, catch_unwind, and make std::env::args
non-empty?
Using the #[start] directive usually doesn't break anything... though I haven't tried it on any large projects.