mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +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
|
package restorable
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
"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.
|
// Restore restores *graphicscommand.Image from the pixels using its state.
|
||||||
func (i *Image) restore() error {
|
func (i *Image) restore() {
|
||||||
w, h := i.Size()
|
w, h := i.Size()
|
||||||
|
|
||||||
// Dispose the internal image after getting its size for safety.
|
// Dispose the internal image after getting its size for safety.
|
||||||
@ -538,16 +537,15 @@ func (i *Image) restore() error {
|
|||||||
i.basePixels = Pixels{}
|
i.basePixels = Pixels{}
|
||||||
i.drawTrianglesHistory = nil
|
i.drawTrianglesHistory = nil
|
||||||
i.stale = false
|
i.stale = false
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
if i.volatile {
|
if i.volatile {
|
||||||
i.image = graphicscommand.NewImage(w, h)
|
i.image = graphicscommand.NewImage(w, h)
|
||||||
i.clear()
|
i.clear()
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
if i.stale {
|
if i.stale {
|
||||||
// TODO: panic here?
|
panic("restorable: pixels must not be stale when restoring")
|
||||||
return errors.New("restorable: pixels must not be stale when restoring")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gimg := graphicscommand.NewImage(w, h)
|
gimg := graphicscommand.NewImage(w, h)
|
||||||
@ -570,7 +568,6 @@ func (i *Image) restore() error {
|
|||||||
i.image = gimg
|
i.image = gimg
|
||||||
i.drawTrianglesHistory = nil
|
i.drawTrianglesHistory = nil
|
||||||
i.stale = false
|
i.stale = false
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dispose disposes the image.
|
// Dispose disposes the image.
|
||||||
|
@ -119,7 +119,8 @@ func RestoreIfNeeded() error {
|
|||||||
if err := graphicscommand.ResetGraphicsDriverState(); err != nil {
|
if err := graphicscommand.ResetGraphicsDriverState(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return theImages.restore()
|
theImages.restore()
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DumpImages dumps all the current images to the specified directory.
|
// DumpImages dumps all the current images to the specified directory.
|
||||||
@ -194,7 +195,7 @@ func (i *images) makeStaleIfDependingOnImpl(target *Image) {
|
|||||||
// restore restores the images.
|
// restore restores the images.
|
||||||
//
|
//
|
||||||
// Restoring means to make all *graphicscommand.Image objects have their textures and framebuffers.
|
// Restoring means to make all *graphicscommand.Image objects have their textures and framebuffers.
|
||||||
func (i *images) restore() error {
|
func (i *images) restore() {
|
||||||
if !needsRestoring() {
|
if !needsRestoring() {
|
||||||
panic("restorable: restore cannot be called when restoring is disabled")
|
panic("restorable: restore cannot be called when restoring is disabled")
|
||||||
}
|
}
|
||||||
@ -251,11 +252,8 @@ func (i *images) restore() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, img := range sorted {
|
for _, img := range sorted {
|
||||||
if err := img.restore(); err != nil {
|
img.restore()
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitializeGraphicsDriverState initializes the graphics driver state.
|
// InitializeGraphicsDriverState initializes the graphics driver state.
|
||||||
|
Loading…
Reference in New Issue
Block a user