mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
shareable: Bug fix: backend's restorable image must be disposed
This commit is contained in:
parent
87daa82ad9
commit
1a335032a2
@ -191,6 +191,7 @@ func (s *Image) dispose() {
|
||||
return
|
||||
}
|
||||
|
||||
s.backend.restorable.Dispose()
|
||||
index := -1
|
||||
for i, sh := range theBackends {
|
||||
if sh == s.backend {
|
||||
@ -313,3 +314,9 @@ func Restore() error {
|
||||
defer backendsM.Unlock()
|
||||
return restorable.Restore()
|
||||
}
|
||||
|
||||
func BackendNumForTesting() int {
|
||||
backendsM.Lock()
|
||||
defer backendsM.Unlock()
|
||||
return len(theBackends)
|
||||
}
|
||||
|
@ -40,13 +40,15 @@ func TestMain(m *testing.M) {
|
||||
os.Exit(code)
|
||||
}
|
||||
|
||||
const bigSize = 2049
|
||||
|
||||
func TestEnsureNotShared(t *testing.T) {
|
||||
// Create img1 and img2 with this size so that the next images are allocated
|
||||
// with non-upper-left location.
|
||||
img1 := NewImage(2049, 100)
|
||||
img1 := NewImage(bigSize, 100)
|
||||
defer img1.Dispose()
|
||||
|
||||
img2 := NewImage(100, 2049)
|
||||
img2 := NewImage(100, bigSize)
|
||||
defer img2.Dispose()
|
||||
|
||||
const size = 32
|
||||
@ -97,3 +99,26 @@ func TestEnsureNotShared(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispose(t *testing.T) {
|
||||
// There are already backend image for the offscreen or something.
|
||||
// Creating a big image and the next image should be created at a new backend.
|
||||
img1 := NewImage(bigSize, bigSize)
|
||||
defer img1.Dispose()
|
||||
|
||||
if BackendNumForTesting() != 1 {
|
||||
t.Errorf("BackendNumForTesting(): got: %d, want: %d", BackendNumForTesting(), 1)
|
||||
}
|
||||
|
||||
img2 := NewImage(bigSize, bigSize)
|
||||
|
||||
if BackendNumForTesting() != 2 {
|
||||
t.Errorf("BackendNumForTesting(): got: %d, want: %d", BackendNumForTesting(), 2)
|
||||
}
|
||||
|
||||
img2.Dispose()
|
||||
|
||||
if BackendNumForTesting() != 1 {
|
||||
t.Errorf("BackendNumForTesting(): got: %d, want: %d", BackendNumForTesting(), 1)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user