From 7b7716471042ee52c4bf797bdbe31b1168e4f4cd Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 12 Apr 2020 20:01:15 +0900 Subject: [PATCH] restorable: Ignore the error when restoring failed due to being not ready (driver.Graphics).BeginFrame tries to restore the images, but the context might be lost at that time yet. If the attempt to restore the context because the driver is not ready, return silently. Fixes #1133 --- internal/driver/graphics.go | 5 +++++ internal/graphicsdriver/opengl/context_js.go | 2 +- internal/restorable/images.go | 7 ++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/driver/graphics.go b/internal/driver/graphics.go index 0ba8fcb38..a4d32d0a5 100644 --- a/internal/driver/graphics.go +++ b/internal/driver/graphics.go @@ -15,6 +15,8 @@ package driver import ( + "errors" + "github.com/hajimehoshi/ebiten/internal/affine" "github.com/hajimehoshi/ebiten/internal/thread" ) @@ -37,6 +39,9 @@ type Graphics interface { MaxImageSize() int } +// GraphicsNotReady represents that the graphics driver is not ready for recovering from the context lost. +var GraphicsNotReady = errors.New("graphics not ready") + type Image interface { Dispose() IsInvalidated() bool diff --git a/internal/graphicsdriver/opengl/context_js.go b/internal/graphicsdriver/opengl/context_js.go index 271f531cc..0111b82d1 100644 --- a/internal/graphicsdriver/opengl/context_js.go +++ b/internal/graphicsdriver/opengl/context_js.go @@ -212,7 +212,7 @@ func (c *context) reset() error { c.gl = js.Value{} c.ensureGL() if c.gl.Call("isContextLost").Bool() { - return fmt.Errorf("opengl: the context is lost") + return driver.GraphicsNotReady } gl := c.gl gl.Call("enable", blend) diff --git a/internal/restorable/images.go b/internal/restorable/images.go index 3885c9d67..1b07a4a8e 100644 --- a/internal/restorable/images.go +++ b/internal/restorable/images.go @@ -17,6 +17,7 @@ package restorable import ( "path/filepath" + "github.com/hajimehoshi/ebiten/internal/driver" "github.com/hajimehoshi/ebiten/internal/graphicscommand" ) @@ -90,7 +91,11 @@ func RestoreIfNeeded() error { } } - if err := graphicscommand.ResetGraphicsDriverState(); err != nil { + err := graphicscommand.ResetGraphicsDriverState() + if err == driver.GraphicsNotReady { + return nil + } + if err != nil { return err } return theImages.restore()