restorable: Panic if an image is stale when restoring

This commit is contained in:
Hajime Hoshi 2019-08-12 17:45:43 +09:00
parent 1156dfdc7e
commit 613b9bc02a
2 changed files with 8 additions and 13 deletions

View File

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

View File

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