rust-mobile / rust-android-examples

Various standalone Rust Android examples
128 stars 22 forks source link

Winit based examples should probably use `EventLoop::run_return` not `EventLoop::run` #3

Closed rib closed 1 year ago

rib commented 1 year ago

Winit's EventLoop ::run() method never returns and the current implementation calls std::process::exit which is a pretty huge hammer.

By forcibly killing the process like this could break normal lifecycle management in case the application is based on a Java subclass of Activity that might want to handle lifecycle events - e.g. to gracefully save state

It also means it's not possible to run more than one Winit event loop per process (e.g. via multiple Activities that are started within the same process).

Since Winit can't really assume that it's safe to call std::process::exit it should maybe just enter an infinite AndroidApp::poll_events loop instead. Additionally it could emit a warning/error since that's also almost certainly not really what anyone wants.

rib commented 1 year ago

This was fixed in https://github.com/rust-mobile/rust-android-examples/pull/4