Skip to content

Commit

Permalink
Fix iOS crash: don't set autoresizing mask (#6535)
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf authored and Wumpf committed Nov 23, 2024
1 parent 08c9d8c commit f286882
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ Bottom level categories:

## Unreleased

## 23.1.0 (2024-11-??)

### Bug fixes

#### 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)

### Themes of this release
Expand Down
38 changes: 20 additions & 18 deletions wgpu-hal/src/metal/surface.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -207,23 +206,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(target_os = "macos")]
{
// 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: std::ffi::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).
Expand Down

0 comments on commit f286882

Please sign in to comment.