mirror of
https://github.com/rust-mobile/android-activity.git
synced 2026-07-10 16:54:10 +00:00
Use NativeWindow::clone_from_ptr() to avoid Segfault
Since f24606cc84 in android-ndk-rs then NativeWindow now implements Clone and Drop which was technically a breaking change since it changed the ownership contract for existing users of NativeWindow::from_ptr(). We now use NativeWindow::clone_from_ptr() to account for the fact that the window will be unconditionally _released() when NativeWindow gets dropped. This addresses a crash I was debugging with the Cpal and Oboe examples which turned out to be nothing to do with the examples themselves.
This commit is contained in:
@@ -269,8 +269,11 @@ impl AndroidAppInner {
|
||||
}
|
||||
MainEvent::InitWindow { .. } => {
|
||||
let win_ptr = (*app_ptr.as_ptr()).window;
|
||||
// It's important that we use ::clone_from_ptr() here
|
||||
// because NativeWindow has a Drop implementation that
|
||||
// will unconditionally _release() the native window
|
||||
*self.native_window.write().unwrap() = Some(
|
||||
NativeWindow::from_ptr(NonNull::new(win_ptr).unwrap()),
|
||||
NativeWindow::clone_from_ptr(NonNull::new(win_ptr).unwrap()),
|
||||
);
|
||||
}
|
||||
MainEvent::TerminateWindow { .. } => {
|
||||
|
||||
@@ -271,8 +271,11 @@ impl AndroidAppInner {
|
||||
}
|
||||
MainEvent::InitWindow { .. } => {
|
||||
let win_ptr = (*app_ptr.as_ptr()).window;
|
||||
// It's important that we use ::clone_from_ptr() here
|
||||
// because NativeWindow has a Drop implementation that
|
||||
// will unconditionally _release() the native window
|
||||
*self.native_window.write().unwrap() =
|
||||
Some(NativeWindow::from_ptr(
|
||||
Some(NativeWindow::clone_from_ptr(
|
||||
NonNull::new(win_ptr).unwrap(),
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user