mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
internal/graphicsdriver/metal: bug fix: the default driver must be initialized on the main thread
Closes #2147
This commit is contained in:
parent
b43312fe80
commit
07a558b38d
@ -346,6 +346,14 @@ const (
|
||||
noStencil
|
||||
)
|
||||
|
||||
var creatingSystemDefaultDeviceSucceeded bool
|
||||
|
||||
func init() {
|
||||
// mtl.CreateSystemDefaultDevice must be called on the main thread (#2147).
|
||||
_, ok := mtl.CreateSystemDefaultDevice()
|
||||
creatingSystemDefaultDeviceSucceeded = ok
|
||||
}
|
||||
|
||||
// NewGraphics creates an implementation of graphicsdriver.Graphcis for Metal.
|
||||
// The returned graphics value is nil iff the error is not nil.
|
||||
func NewGraphics() (graphicsdriver.Graphics, error) {
|
||||
@ -353,13 +361,10 @@ func NewGraphics() (graphicsdriver.Graphics, error) {
|
||||
return nil, fmt.Errorf("metal: Metal is not supported in this environment")
|
||||
}
|
||||
|
||||
// Initialize isMetalAvailable on the main thread.
|
||||
// TODO: Now ui.newGraphicsDriver is called on the main thread. Add an assertion.
|
||||
|
||||
// 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 _, ok := mtl.CreateSystemDefaultDevice(); !ok {
|
||||
if !creatingSystemDefaultDeviceSucceeded {
|
||||
return nil, fmt.Errorf("metal: mtl.CreateSystemDefaultDevice failed")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user