Skip to content

Commit

Permalink
Remove panicking in Android's HasRawWindowHandle
Browse files Browse the repository at this point in the history
Instead we now just return a NULL handle, and warn that the native window couldn't be found.
  • Loading branch information
madsmtm committed Nov 19, 2021
1 parent 8481624 commit adc7a2b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/platform_impl/android/mod.rs
Expand Up @@ -595,7 +595,7 @@ impl Window {
if let Some(native_window) = ndk_glue::native_window().as_ref() {
handle.a_native_window = unsafe { native_window.ptr().as_mut() as *mut _ as *mut _ }
} else {
panic!("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.");
log::warn!("Cannot get the native window while the application is suspended (between Event::Suspended and Event::Resumed).");
};
RawWindowHandle::AndroidNdk(handle)
}
Expand Down
3 changes: 1 addition & 2 deletions src/window.rs
Expand Up @@ -889,8 +889,7 @@ unsafe impl raw_window_handle::HasRawWindowHandle for Window {
///
/// ## Platform-specific
///
/// - **Android:** Only available after receiving the Resumed event and before Suspended. *If you*
/// *try to get the handle outside of that period, this function will panic*!
/// - **Android:** Not available between receiving the Suspended and Resumed events.
fn raw_window_handle(&self) -> raw_window_handle::RawWindowHandle {
self.window.raw_window_handle()
}
Expand Down

0 comments on commit adc7a2b

Please sign in to comment.