gpui: Fix crash when starting Zed on macOS during texture creation (#36382)

Closes #36229

Fix zero-sized texture creation that triggers a SIGABRT in the Metal
renderer. Not sure why this happens yet, but it likely occurs when
`native_window.contentView()` returns a zero `NSSize` during initial
window creation, before the view size is computed.

Release Notes:

- Fixed a rare startup crash on macOS.
This commit is contained in:
Smit Barmase 2025-08-18 08:16:17 +05:30 committed by GitHub
parent 2dbc951058
commit 7dc4adbd40
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -314,6 +314,15 @@ impl MetalRenderer {
}
fn update_path_intermediate_textures(&mut self, size: Size<DevicePixels>) {
// We are uncertain when this happens, but sometimes size can be 0 here. Most likely before
// the layout pass on window creation. Zero-sized texture creation causes SIGABRT.
// https://github.com/zed-industries/zed/issues/36229
if size.width.0 <= 0 || size.height.0 <= 0 {
self.path_intermediate_texture = None;
self.path_intermediate_msaa_texture = None;
return;
}
let texture_descriptor = metal::TextureDescriptor::new();
texture_descriptor.set_width(size.width.0 as u64);
texture_descriptor.set_height(size.height.0 as u64);