-
Notifications
You must be signed in to change notification settings - Fork 927
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
Compiling on windows for android errors #1886 #2118
Changes from all 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; | ||
} | ||
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
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 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! 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. 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 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 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, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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?
WindowDestroyed
already sendsSuspended
, why is that not enough?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rust-windowing/glutin#904
rust-windowing/glutin#1313
Check this comment:
rust-windowing/glutin#1313 (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:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More discussion on this:
rust-mobile/ndk#117
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The linked docs are pretty clear on this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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
winit
, theSuspended
andResumed
events are not right as they serve a different purpose.onPause
andonResume
should result in aWindowEvent::Focused
.Perhaps we should rename
Suspended
andResumed
to more closely represent the graphics state needing to be forcibly destroyed and recreated, respectively?There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
When do resourced need to be created, when do they need to be destroyed.
And yes you are right, it would be much more coherent, if these events would be of type
WindowEvent
. Like i'm handling the resize event:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the android behaviour:
Focus can not be used to create the device, as i get following events when starting the main loop:
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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
WindowCreated
and destroyed before or duringWindowDestroyed
. Applications are free to perform this elsewhere, as long as they synchronize properly with the events (ie. hold on to the lock fromnative_window()
, and destroy your resources followed by releasing this lock wheneverWindowDestroyed
is called).At what level are you logging this? Is logging initialized early enough (ie. in
ndk_glue::main
)? If Android doesn't give your application a window there's nothing to render to.My best guess is "resume" in your list is referring to
event::Event::Resumed
, ie. triggered onndk_glue::Event::WindowCreated
?