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
This commit is contained in:
Hajime Hoshi 2020-04-12 20:01:15 +09:00
parent e16a4cd85c
commit 7b77164710
3 changed files with 12 additions and 2 deletions

View File

@ -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

View File

@ -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)

View File

@ -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()