Avoid panic when unable to access a GPU

This will remove noise from our panic logs.

Co-authored-by: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2022-07-18 14:13:12 -07:00
parent 59366a5c44
commit 7998771d9f

View file

@ -11,8 +11,8 @@ use crate::{
use block::ConcreteBlock; use block::ConcreteBlock;
use cocoa::{ use cocoa::{
appkit::{ appkit::{
CGPoint, NSApplication, NSBackingStoreBuffered, NSScreen, NSView, NSViewHeightSizable, CGPoint, NSApplication, NSBackingStoreBuffered, NSModalResponse, NSScreen, NSView,
NSViewWidthSizable, NSWindow, NSWindowButton, NSWindowStyleMask, NSViewHeightSizable, NSViewWidthSizable, NSWindow, NSWindowButton, NSWindowStyleMask,
}, },
base::{id, nil}, base::{id, nil},
foundation::{NSAutoreleasePool, NSInteger, NSSize, NSString}, foundation::{NSAutoreleasePool, NSInteger, NSSize, NSString},
@ -228,8 +228,16 @@ impl Window {
native_window.setFrame_display_(screen.visibleFrame(), YES); native_window.setFrame_display_(screen.visibleFrame(), YES);
} }
let device = let device = if let Some(device) = metal::Device::system_default() {
metal::Device::system_default().expect("could not find default metal device"); device
} else {
let alert: id = msg_send![class!(NSAlert), alloc];
let _: () = msg_send![alert, init];
let _: () = msg_send![alert, setAlertStyle: 2];
let _: () = msg_send![alert, setMessageText: ns_string("Unable to access a compatible graphics device")];
let _: NSModalResponse = msg_send![alert, runModal];
std::process::exit(1);
};
let layer: id = msg_send![class!(CAMetalLayer), layer]; let layer: id = msg_send![class!(CAMetalLayer), layer];
let _: () = msg_send![layer, setDevice: device.as_ptr()]; let _: () = msg_send![layer, setDevice: device.as_ptr()];