examples/contextlost: Bug fix: don't crash on Edge

Fixes #613
This commit is contained in:
Hajime Hoshi 2018-05-14 00:35:40 +09:00
parent a92cc0f4b3
commit 569639d485

View File

@ -48,8 +48,17 @@ func update(screen *ebiten.Image) error {
doc := js.Global.Get("document")
canvas := doc.Call("getElementsByTagName", "canvas").Index(0)
context := canvas.Call("getContext", "webgl")
context.Call("getExtension", "WEBGL_lose_context").Call("loseContext")
fmt.Println("Context Lost!")
if context == nil {
context = canvas.Call("getContext", "experimental-webgl")
}
// Edge might not support the extension. See
// https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_lose_context
if ext := context.Call("getExtension", "WEBGL_lose_context"); ext != nil {
ext.Call("loseContext")
fmt.Println("Context Lost!")
} else {
fmt.Println("Fail to force context lost. Edge might not support the extension yet.")
}
return nil
}