From adc7a2b61d43dd3a96964fd4fa5945cd64fe8d86 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Fri, 19 Nov 2021 09:42:39 +0100 Subject: [PATCH] Remove panicking in Android's HasRawWindowHandle Instead we now just return a NULL handle, and warn that the native window couldn't be found. --- src/platform_impl/android/mod.rs | 2 +- src/window.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 0691bcc1e8..09c1b969bd 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -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) } diff --git a/src/window.rs b/src/window.rs index 59c8c59f2e..5c55378d20 100644 --- a/src/window.rs +++ b/src/window.rs @@ -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() }