From 52a5456fbcf0c4dd78ca7d0d84f72938a1098e11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 13 Nov 2024 01:48:14 +0100 Subject: [PATCH 1/4] don't set autoresizing mask on ios as that's not supported --- wgpu-hal/src/metal/surface.rs | 37 +++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/wgpu-hal/src/metal/surface.rs b/wgpu-hal/src/metal/surface.rs index 668b602474..d00ce2f25a 100644 --- a/wgpu-hal/src/metal/surface.rs +++ b/wgpu-hal/src/metal/surface.rs @@ -207,23 +207,26 @@ impl super::Surface { let new_layer: *mut Object = msg_send![class!(CAMetalLayer), new]; let () = msg_send![root_layer, addSublayer: new_layer]; - // Automatically resize the sublayer's frame to match the - // superlayer's bounds. - // - // Note that there is a somewhat hidden design decision in this: - // We define the `width` and `height` in `configure` to control - // the `drawableSize` of the layer, while `bounds` and `frame` are - // outside of the user's direct control - instead, though, they - // can control the size of the view (or root layer), and get the - // desired effect that way. - // - // We _could_ also let `configure` set the `bounds` size, however - // that would be inconsistent with using the root layer directly - // (as we may do, see above). - let width_sizable = 1 << 1; // kCALayerWidthSizable - let height_sizable = 1 << 4; // kCALayerHeightSizable - let mask: c_uint = width_sizable | height_sizable; - let () = msg_send![new_layer, setAutoresizingMask: mask]; + #[cfg(not(target_os = "ios"))] + { + // Automatically resize the sublayer's frame to match the + // superlayer's bounds. + // + // Note that there is a somewhat hidden design decision in this: + // We define the `width` and `height` in `configure` to control + // the `drawableSize` of the layer, while `bounds` and `frame` are + // outside of the user's direct control - instead, though, they + // can control the size of the view (or root layer), and get the + // desired effect that way. + // + // We _could_ also let `configure` set the `bounds` size, however + // that would be inconsistent with using the root layer directly + // (as we may do, see above). + let width_sizable = 1 << 1; // kCALayerWidthSizable + let height_sizable = 1 << 4; // kCALayerHeightSizable + let mask: c_uint = width_sizable | height_sizable; + let () = msg_send![new_layer, setAutoresizingMask: mask]; + } // Specify the relative size that the auto resizing mask above // will keep (i.e. tell it to fill out its superlayer). From b13177a48bed93ff9810eb886e44987c0d1778db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 13 Nov 2024 01:59:23 +0100 Subject: [PATCH 2/4] gate the import too --- wgpu-hal/src/metal/surface.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/wgpu-hal/src/metal/surface.rs b/wgpu-hal/src/metal/surface.rs index d00ce2f25a..68e321cdf9 100644 --- a/wgpu-hal/src/metal/surface.rs +++ b/wgpu-hal/src/metal/surface.rs @@ -1,6 +1,5 @@ #![allow(clippy::let_unit_value)] // `let () =` being used to constrain result type -use std::ffi::c_uint; use std::mem::ManuallyDrop; use std::ptr::NonNull; use std::sync::Once; @@ -224,7 +223,7 @@ impl super::Surface { // (as we may do, see above). let width_sizable = 1 << 1; // kCALayerWidthSizable let height_sizable = 1 << 4; // kCALayerHeightSizable - let mask: c_uint = width_sizable | height_sizable; + let mask: std::ffi::c_uint = width_sizable | height_sizable; let () = msg_send![new_layer, setAutoresizingMask: mask]; } From 9957ee74f0a973ee55e1ffe5e73e9780dc749ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Mockers?= Date: Wed, 13 Nov 2024 21:34:34 +0100 Subject: [PATCH 3/4] check on macOS target_os Co-authored-by: Mads Marquart --- wgpu-hal/src/metal/surface.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu-hal/src/metal/surface.rs b/wgpu-hal/src/metal/surface.rs index 68e321cdf9..b35c73c910 100644 --- a/wgpu-hal/src/metal/surface.rs +++ b/wgpu-hal/src/metal/surface.rs @@ -206,7 +206,7 @@ impl super::Surface { let new_layer: *mut Object = msg_send![class!(CAMetalLayer), new]; let () = msg_send![root_layer, addSublayer: new_layer]; - #[cfg(not(target_os = "ios"))] + #[cfg(target_os = "macos")] { // Automatically resize the sublayer's frame to match the // superlayer's bounds. From 4c042155378585a54600c27ee09911aae50152ff Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Fri, 15 Nov 2024 09:06:09 +0100 Subject: [PATCH 4/4] add changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85e81fe9b5..c4e2f3b661 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -136,6 +136,10 @@ By @ErichDonGubler in [#6456](https://github.com/gfx-rs/wgpu/pull/6456), [#6148] - Fix surface capabilities being advertised when its query failed. By @wumpf in [#6510](https://github.com/gfx-rs/wgpu/pull/6510) +### Metal + +- Fix surface creation crashing on iOS. By @mockersf in [#6535](https://github.com/gfx-rs/wgpu/pull/6535) + ## 23.0.0 (2024-10-25)