mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 10:42:42 +01:00
restorable: Panic if an image is stale when restoring
This commit is contained in:
parent
1156dfdc7e
commit
613b9bc02a
@ -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.
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user