restorable: Bug fix: dummyImage must be restored first

Fixes #791
This commit is contained in:
Hajime Hoshi 2019-01-21 00:36:37 +09:00
parent 4d05baf97c
commit eeb8fea778
2 changed files with 16 additions and 7 deletions

View File

@ -55,13 +55,17 @@ type Image struct {
w2 int
h2 int
// priority indicates whether the image is restored in high priority when context-lost happens.
priority bool
}
var dummyImage *Image
func init() {
dummyImage = &Image{
image: graphicscommand.NewImage(16, 16),
image: graphicscommand.NewImage(16, 16),
priority: true,
}
theImages.add(dummyImage)
}
@ -98,11 +102,7 @@ func NewScreenFramebufferImage(width, height int) *Image {
func (i *Image) clear() {
// There are not 'drawImageHistoryItem's for this image and dummyImage.
// This means dummyImage might not be restored yet when this image is restored.
// However, that's ok since this image will be stale or have its updated pixel data soon,
// and this image can be restored without dummyImage.
//
// dummyImage should be restored later anyway.
// As dummyImage is a priority image, this is restored faster than other regular images.
w, h := i.Size()
sw, sh := dummyImage.Size()
dw := graphics.NextPowerOf2Int(w)

View File

@ -164,7 +164,9 @@ func (i *images) restore() error {
}
images := map[*Image]struct{}{}
for i := range i.images {
images[i] = struct{}{}
if !i.priority {
images[i] = struct{}{}
}
}
edges := map[edge]struct{}{}
for t := range images {
@ -172,7 +174,13 @@ func (i *images) restore() error {
edges[edge{source: s, target: t}] = struct{}{}
}
}
sorted := []*Image{}
for i := range i.images {
if i.priority {
sorted = append(sorted, i)
}
}
for len(images) > 0 {
// current repesents images that have no incoming edges.
current := map[*Image]struct{}{}
@ -198,6 +206,7 @@ func (i *images) restore() error {
delete(edges, e)
}
}
for _, img := range sorted {
if err := img.restore(); err != nil {
return err