From 613b9bc02a71a730c7781f9670dbc06bce5caed8 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 12 Aug 2019 17:45:43 +0900 Subject: [PATCH] restorable: Panic if an image is stale when restoring --- internal/restorable/image.go | 11 ++++------- internal/restorable/images.go | 10 ++++------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/internal/restorable/image.go b/internal/restorable/image.go index 8aa9dc73a..cc50b0d85 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -15,7 +15,6 @@ package restorable import ( - "errors" "fmt" "github.com/hajimehoshi/ebiten/internal/affine" @@ -525,7 +524,7 @@ func (i *Image) hasDependency() bool { } // Restore restores *graphicscommand.Image from the pixels using its state. -func (i *Image) restore() error { +func (i *Image) restore() { w, h := i.Size() // Dispose the internal image after getting its size for safety. @@ -538,16 +537,15 @@ func (i *Image) restore() error { i.basePixels = Pixels{} i.drawTrianglesHistory = nil i.stale = false - return nil + return } if i.volatile { i.image = graphicscommand.NewImage(w, h) i.clear() - return nil + return } if i.stale { - // TODO: panic here? - return errors.New("restorable: pixels must not be stale when restoring") + panic("restorable: pixels must not be stale when restoring") } gimg := graphicscommand.NewImage(w, h) @@ -570,7 +568,6 @@ func (i *Image) restore() error { i.image = gimg i.drawTrianglesHistory = nil i.stale = false - return nil } // Dispose disposes the image. diff --git a/internal/restorable/images.go b/internal/restorable/images.go index 5711eaeea..c26eb7288 100644 --- a/internal/restorable/images.go +++ b/internal/restorable/images.go @@ -119,7 +119,8 @@ func RestoreIfNeeded() error { if err := graphicscommand.ResetGraphicsDriverState(); err != nil { return err } - return theImages.restore() + theImages.restore() + return nil } // DumpImages dumps all the current images to the specified directory. @@ -194,7 +195,7 @@ func (i *images) makeStaleIfDependingOnImpl(target *Image) { // restore restores the images. // // Restoring means to make all *graphicscommand.Image objects have their textures and framebuffers. -func (i *images) restore() error { +func (i *images) restore() { if !needsRestoring() { panic("restorable: restore cannot be called when restoring is disabled") } @@ -251,11 +252,8 @@ func (i *images) restore() error { } for _, img := range sorted { - if err := img.restore(); err != nil { - return err - } + img.restore() } - return nil } // InitializeGraphicsDriverState initializes the graphics driver state.