android-rs-glue icon indicating copy to clipboard operation
android-rs-glue copied to clipboard

Opening an app twice results in a crash

Open gmorenz opened this issue 8 years ago • 6 comments

Steps to reproduce:

  1. Create fn main() { loop {} } app
  2. Open the app
  3. Hit the back arrow
  4. 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.

gmorenz avatar Jun 09 '16 16:06 gmorenz

The android_main function is supposed to detect that and not run the app a second time.

tomaka avatar Jun 09 '16 16:06 tomaka

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.

gmorenz avatar Jun 09 '16 16:06 gmorenz

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?

gmorenz avatar Jun 09 '16 16:06 gmorenz

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.

tomaka avatar Jun 09 '16 16:06 tomaka

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.

tomaka avatar Jun 09 '16 16:06 tomaka

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.

gmorenz avatar Jun 09 '16 16:06 gmorenz