mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
Revert "restorable: Bug fix: Guard images by mutex"
This reverts commit 7967f68073
.
Reason: Wrong fix (syncing should be done at shareable package)
This commit is contained in:
parent
7967f68073
commit
ccacf015c2
@ -16,7 +16,6 @@ package restorable
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphicscommand"
|
"github.com/hajimehoshi/ebiten/internal/graphicscommand"
|
||||||
)
|
)
|
||||||
@ -43,8 +42,6 @@ func EnableRestoringForTesting() {
|
|||||||
type images struct {
|
type images struct {
|
||||||
images map[*Image]struct{}
|
images map[*Image]struct{}
|
||||||
lastTarget *Image
|
lastTarget *Image
|
||||||
|
|
||||||
m sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// theImages represents the images for the current process.
|
// theImages represents the images for the current process.
|
||||||
@ -75,15 +72,8 @@ func Restore() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Images() []image.Image {
|
func Images() []image.Image {
|
||||||
return theImages.images()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *images) images() []image.Image {
|
|
||||||
i.m.Lock()
|
|
||||||
defer i.m.Unlock()
|
|
||||||
|
|
||||||
var imgs []image.Image
|
var imgs []image.Image
|
||||||
for img := range i.images {
|
for img := range theImages.images {
|
||||||
if img.volatile {
|
if img.volatile {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -113,27 +103,21 @@ func (i *images) images() []image.Image {
|
|||||||
|
|
||||||
// add adds img to the images.
|
// add adds img to the images.
|
||||||
func (i *images) add(img *Image) {
|
func (i *images) add(img *Image) {
|
||||||
i.m.Lock()
|
|
||||||
i.images[img] = struct{}{}
|
i.images[img] = struct{}{}
|
||||||
i.m.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove removes img from the images.
|
// remove removes img from the images.
|
||||||
func (i *images) remove(img *Image) {
|
func (i *images) remove(img *Image) {
|
||||||
i.m.Lock()
|
|
||||||
i.makeStaleIfDependingOnImpl(img)
|
i.makeStaleIfDependingOnImpl(img)
|
||||||
delete(i.images, img)
|
delete(i.images, img)
|
||||||
i.m.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolveStaleImages resolves stale images.
|
// resolveStaleImages resolves stale images.
|
||||||
func (i *images) resolveStaleImages() {
|
func (i *images) resolveStaleImages() {
|
||||||
i.m.Lock()
|
|
||||||
i.lastTarget = nil
|
i.lastTarget = nil
|
||||||
for img := range i.images {
|
for img := range i.images {
|
||||||
img.resolveStale()
|
img.resolveStale()
|
||||||
}
|
}
|
||||||
i.m.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// makeStaleIfDependingOn makes all the images stale that depend on target.
|
// makeStaleIfDependingOn makes all the images stale that depend on target.
|
||||||
@ -141,10 +125,8 @@ func (i *images) resolveStaleImages() {
|
|||||||
// When target is changed, all images depending on target can't be restored with target.
|
// When target is changed, all images depending on target can't be restored with target.
|
||||||
// makeStaleIfDependingOn is called in such situation.
|
// makeStaleIfDependingOn is called in such situation.
|
||||||
func (i *images) makeStaleIfDependingOn(target *Image) {
|
func (i *images) makeStaleIfDependingOn(target *Image) {
|
||||||
i.m.Lock()
|
|
||||||
// Avoid defer for performance
|
// Avoid defer for performance
|
||||||
i.makeStaleIfDependingOnImpl(target)
|
i.makeStaleIfDependingOnImpl(target)
|
||||||
i.m.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *images) makeStaleIfDependingOnImpl(target *Image) {
|
func (i *images) makeStaleIfDependingOnImpl(target *Image) {
|
||||||
@ -168,9 +150,6 @@ func (i *images) restore() error {
|
|||||||
panic("restorable: restore cannot be called when restoring is disabled")
|
panic("restorable: restore cannot be called when restoring is disabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
i.m.Lock()
|
|
||||||
defer i.m.Unlock()
|
|
||||||
|
|
||||||
// Dispose image explicitly
|
// Dispose image explicitly
|
||||||
for img := range i.images {
|
for img := range i.images {
|
||||||
img.image.Dispose()
|
img.image.Dispose()
|
||||||
|
Loading…
Reference in New Issue
Block a user