From be850e483af07cba6124311acab2cacd5925ba95 Mon Sep 17 00:00:00 2001 From: Brad Date: Thu, 29 Oct 2020 16:23:46 -0500 Subject: [PATCH] Document Android raw_window_handle requirements (#1749) * Add docs describing raw_winow_handle on android * Run cargo fmt * Change raw_window_handle panic to give more info --- src/platform_impl/android/mod.rs | 2 +- src/window.rs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index be19af4f..c0f80dca 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -505,7 +505,7 @@ impl Window { let a_native_window = if let Some(native_window) = ndk_glue::native_window().as_ref() { unsafe { native_window.ptr().as_mut() as *mut _ as *mut _ } } else { - panic!("native window null"); + 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."); }; let mut handle = raw_window_handle::android::AndroidHandle::empty(); handle.a_native_window = a_native_window; diff --git a/src/window.rs b/src/window.rs index ed8e7af3..c8f45d10 100644 --- a/src/window.rs +++ b/src/window.rs @@ -784,6 +784,12 @@ impl Window { } unsafe impl raw_window_handle::HasRawWindowHandle for Window { + /// Returns a `raw_window_handle::RawWindowHandle` for the 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*! fn raw_window_handle(&self) -> raw_window_handle::RawWindowHandle { self.window.raw_window_handle() }