Skip to content

Commit

Permalink
internal/graphicsdriver/metal: improve an error message for Metal ini…
Browse files Browse the repository at this point in the history
…tialization

Updates #2732
  • Loading branch information
hajimehoshi committed Aug 26, 2023
1 parent 4116fd3 commit 592d6c5
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions internal/graphicsdriver/metal/graphics_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,19 @@ const (
noStencil
)

var systemDefaultDevice mtl.Device
var (
systemDefaultDevice mtl.Device
systemDefaultDeviceErr error
)

func init() {
// mtl.CreateSystemDefaultDevice must be called on the main thread (#2147).
d, err := mtl.CreateSystemDefaultDevice()
if err == nil {
systemDefaultDevice = d
if err != nil {
systemDefaultDeviceErr = err
return
}
systemDefaultDevice = d
}

// NewGraphics creates an implementation of graphicsdriver.Graphics for Metal.
Expand All @@ -91,8 +96,8 @@ func NewGraphics() (graphicsdriver.Graphics, error) {
// On old mac devices like iMac 2011, Metal is not supported (#779).
// TODO: Is there a better way to check whether Metal is available or not?
// It seems OK to call MTLCreateSystemDefaultDevice multiple times, so this should be fine.
if systemDefaultDevice == (mtl.Device{}) {
return nil, fmt.Errorf("metal: mtl.CreateSystemDefaultDevice failed")
if systemDefaultDeviceErr != nil {
return nil, fmt.Errorf("metal: mtl.CreateSystemDefaultDevice failed: %w", systemDefaultDeviceErr)
}

g := &Graphics{}
Expand Down

0 comments on commit 592d6c5

Please sign in to comment.