-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Compiling on windows for android errors #1886 #2118
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
Changes from 11 commits
87ed5e5
828496d
5675b1b
15627c2
00d1e3a
708f788
d8a3f00
0257d6e
c72f267
d8cc2a6
8e32192
9e082fa
7ff2a42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -144,8 +144,24 @@ impl<T: 'static> EventLoop<T> { | |
| event::Event::Suspended | ||
| ); | ||
| } | ||
| Event::Pause => self.running = false, | ||
| Event::Resume => self.running = true, | ||
| Event::Pause => { | ||
| call_event_handler!( | ||
| event_handler, | ||
| self.window_target(), | ||
| control_flow, | ||
| event::Event::Suspended | ||
| ); | ||
| self.running = false; | ||
| } | ||
| Event::Resume => { | ||
| call_event_handler!( | ||
| event_handler, | ||
| self.window_target(), | ||
| control_flow, | ||
| event::Event::Resumed | ||
| ); | ||
| self.running = true; | ||
| } | ||
|
Comment on lines
+147
to
+164
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please add some information about why this is necessary, maybe with a few links to the Android docs?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rust-windowing/glutin#904 Check this comment: Android has some special windows context handling, where context cannot be resused after resuming. Data has to be reinitialized. Therefore we need to handle those events. Old version just sets flags:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More discussion on this:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I doubt that is correct: https://developer.android.com/guide/components/activities/activity-lifecycle#onpause
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Why? We need to handle pause and resume events on android side. The point is, no one can tell how long the app was paused, maybe it was send to background for several hours... We need to free graphics resources here. If the app resumes, it's possible that original window context is not valid anymore. We cannot keep rendering to that destroyed window. Just settings flags is not an option. These both events are the point where graphics need to be handled. I've made an consumer of these events, that is working fine: match event {
Event::Resumed => {
// ANDROID: only create if native window is available
#[cfg(target_os = "android")]
{
// enable immersive mode
enable_immersive();
// create graphics context (mabye it still exists)
if self.device_ctx.is_none() && ndk_glue::native_window().is_some() {
self.device_ctx = Some(DeviceContext::new(_event_loop));
if let Some(device_ctx) = self.device_ctx.as_mut() {
// call create device callback
self.runner.create_device(&device_ctx.gl);
}
}
}
// call resume callback
paused = false;
}
Event::Suspended => {
// call pause callback
paused = true;
// ANDROID: only destroy if native window is available
#[cfg(target_os = "android")]
{
if self.device_ctx.is_some() && ndk_glue::native_window().is_some() {
if let Some(device_ctx) = self.device_ctx.as_mut() {
// call destroy device callback
self.runner.destroy_device(&device_ctx.gl);
}
self.device_ctx = None;
}
}
}
...
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The linked docs are pretty clear on this:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In other words: while I do agree it might be nice to forward these events through
Perhaps we should rename
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, maybe I abused these events to get my context handling correctly. The main point is, that we must not lose important android events. We need to be able to react on window changes. And yes you are right, it would be much more coherent, if these events would be of type Event::WindowEvent { event, .. } => match event {
WindowEvent::Resized(physical_size) => {
if let Some(device_ctx) = self.device_ctx.as_mut() {
device_ctx.window_context.resize(physical_size);
// call resize device callback
self.runner.resize_device(
&device_ctx.gl,
physical_size.width,
physical_size.height,
);
}
}
....
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked the android behaviour:
There is no window create event or such. The focus event is too late to use it for creation, as resize event is already executed.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Nor is the android documentation suggesting to. Swapchain creation and deletion "must" be tied to window creation and destroying: you can do it whenever you like, as long as it is created after
At what level are you logging this? Is logging initialized early enough (ie. in |
||
| Event::ConfigChanged => { | ||
| let am = ndk_glue::native_activity().asset_manager(); | ||
| let config = Configuration::from_asset_manager(&am); | ||
|
|
@@ -169,6 +185,18 @@ impl<T: 'static> EventLoop<T> { | |
| ); | ||
| } | ||
| } | ||
| Event::Destroy => { | ||
| let event = event::Event::WindowEvent { | ||
| window_id: window::WindowId(WindowId), | ||
| event: event::WindowEvent::CloseRequested, | ||
| }; | ||
| call_event_handler!( | ||
| event_handler, | ||
| self.window_target(), | ||
| control_flow, | ||
| event | ||
| ); | ||
| } | ||
|
Comment on lines
+188
to
+199
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems wrong to send
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I get everthing correctly, there is no direct destroy in android. There is just a request to destroy the app. It's send to background, to make reopening faster. If there are not enough resources available, the app gets destroyed, but those events are handled by OS. I will check this again!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked this. I'm open to change this to WindowEvent::Destroyed. I think it's some sort of interpretation: If this is the only problem, i will change it.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is dispatched as a
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be best, if we can strictly divide Event and WindowEvent. The questio is, if winit fires all those events correctly, also in android environment. Again, we must not lose any important events for graphics handling. I will rework the complete event section for android. To make some nice mapping: // starting app // send to background // close
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
As said it'd be great if this event is handled properly in (Tangent: theoretically it'd be nice if every platform could emit these events for swapchain creation and destruction, making the whole thing more generic. Even better: we provide the
Regarding this prior question: Whenever this function/event is called, you are supposed to release all resources related to the window (again: the swapchain) and return from this function ( |
||
| Event::WindowHasFocus => { | ||
| call_event_handler!( | ||
| event_handler, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.