-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sometimes running apps panicked on the Android Emulator #116
Comments
That is apparently the looper which has not been initialized yet: I don't think we should be returning from |
@MarijnS95 Thank you for suggestion! How can we do this in the best way? |
@Gordon-F There are numerous ways to solve this; for example wrapping the static global Another, simpler-to-write solution is to block Finally we can also create a temporary mutex inside |
@MarijnS95 Thank you for the detailed explanation! I've tried your solution with RustStdoutStderr: thread '<unnamed>' panicked at 'Cannot get the native window, it's null and will always be null before Event::Resumed and after Event::Suspended. Make sure you only call this function between those events.', /Users/indish/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.24.0/src/platform_impl/android/mod.rs:530:13
RustStdoutStderr: note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace This is strange since at the beginning of the application I am waiting for fn main() {
{
log::info!("App started. Waiting for NativeScreen");
loop {
match ndk_glue::native_window().as_ref() {
Some(_) => {
log::info!("NativeScreen Found:{:?}", ndk_glue::native_window());
break;
}
None => (),
}
}
}
run();
} |
@Gordon-F I assume you changed your You should instead add that to a patch section like: [patch.crates-io]
ndk-glue = { path = "..../android-ndk-rs/ndk-glue" } Right now there are likely two versions of |
For acquiring the window handle it should be done during the event loop only, see for example https://github.com/msiglreith/wgpu-rs/blob/android/examples/hello-triangle/main.rs#L108-L119 At any other place it may or may not give you proper values resulting in a panic |
Yes, that too - you should not need to wait for a native window before starting your application, use the Also note that |
Android only performs additional initialization like providing an input queue through `onInputQueueCreated` after the main initialization function (`ANativeActivity_onCreate`) returns. In some cases it is possible that the main thread spawned here hasn't attached a looper to its thread and assigned it to the accompanying `LOOPER` static variable yet, resulting in a `None` unwrap when Android provides us with an input queue. This race condition is simply solved by not returning from `fn init()` (`ANativeActivity_onCreate`) until the thread has finished its setup, through wrapping `LOOPER` in a `Mutex` and using a condition variable to signal when it is ready. This condition is intentionally not exposed to `on_input_queue_created` may we ever have a cleanup procedure that sets `LOOPER` back to `None`; any call to `onInputQueueCreated` in that state would be an error and should not block indefinitely. The `LOOPER` should simply be ready by the time `fn init()` returns. Fixes rust-mobile#116
Android only performs additional initialization like providing an input queue through `onInputQueueCreated` after the main initialization function (`ANativeActivity_onCreate`) returns. In some cases it is possible that the main thread spawned here hasn't attached a looper to its thread and assigned it to the accompanying `LOOPER` static variable yet, resulting in a `None` unwrap when Android provides us with an input queue. This race condition is simply solved by not returning from `fn init()` (`ANativeActivity_onCreate`) until the thread has finished its setup, through wrapping `LOOPER` in a `Mutex` and using a condition variable to signal when it is ready. This condition is intentionally not exposed to `on_input_queue_created` may we ever have a cleanup procedure that sets `LOOPER` back to `None`; any call to `onInputQueueCreated` in that state would be an error and should not block indefinitely. The `LOOPER` should simply be ready by the time `fn init()` returns. Fixes rust-mobile#116
Android only performs additional initialization like providing an input queue through `onInputQueueCreated` after the main initialization function (`ANativeActivity_onCreate`) returns. In some cases it is possible that the main thread spawned here hasn't attached a looper to its thread and assigned it to the accompanying `LOOPER` static variable yet, resulting in a `None` unwrap when Android provides us with an input queue. This race condition is simply solved by not returning from `fn init()` (`ANativeActivity_onCreate`) until the thread has finished its setup, through wrapping `LOOPER` in a `Mutex` and using a condition variable to signal when it is ready. This condition is intentionally not exposed to `on_input_queue_created` may we ever have a cleanup procedure that sets `LOOPER` back to `None`; any call to `onInputQueueCreated` in that state would be an error and should not block indefinitely. The `LOOPER` should simply be ready by the time `fn init()` returns. Fixes #116
Sometimes running apps panicked on the Android Emulator with following error:
This error is constantly repeated in CI: https://github.com/gfx-rs/gfx/runs/1738010575?check_suite_focus=true
Sometimes I saw this error on my dev machine (MacOS host), but restart the Android Emulator fixed it. And I never saw this error on a real device.
The text was updated successfully, but these errors were encountered: