mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-02 22:14:29 +01:00
internal/atlas: backends for unmanaged images were never released
Closes #3030
This commit is contained in:
parent
3f91d8cdf1
commit
2a22260d14
@ -69,3 +69,9 @@ func DeferredFuncCountForTesting() int {
|
||||
defer deferredM.Unlock()
|
||||
return len(deferred)
|
||||
}
|
||||
|
||||
func BackendCountForTesting() int {
|
||||
backendsM.Lock()
|
||||
defer backendsM.Unlock()
|
||||
return len(theBackends)
|
||||
}
|
||||
|
@ -689,12 +689,7 @@ func (i *Image) deallocate() {
|
||||
return
|
||||
}
|
||||
|
||||
if !i.isOnAtlas() {
|
||||
i.backend.image.Dispose()
|
||||
i.backend.image = nil
|
||||
return
|
||||
}
|
||||
|
||||
if i.isOnAtlas() {
|
||||
i.backend.page.Free(i.node)
|
||||
if !i.backend.page.IsEmpty() {
|
||||
// As this part can be reused, this should be cleared explicitly.
|
||||
@ -702,6 +697,7 @@ func (i *Image) deallocate() {
|
||||
i.backend.clearPixels(r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
i.backend.image.Dispose()
|
||||
i.backend.image = nil
|
||||
|
@ -881,4 +881,26 @@ func TestGC(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDallocateUnmanagedImageBackends(t *testing.T) {
|
||||
const w, h = 16, 16
|
||||
img0 := atlas.NewImage(w, h, atlas.ImageTypeUnmanaged)
|
||||
img1 := atlas.NewImage(w, h, atlas.ImageTypeUnmanaged)
|
||||
|
||||
// Call DrawTriangles to ensure the images are on backends.
|
||||
vs := quadVertices(w, h, 0, 0, 1)
|
||||
is := graphics.QuadIndices()
|
||||
dr := image.Rect(0, 0, w, h)
|
||||
img0.DrawTriangles([graphics.ShaderSrcImageCount]*atlas.Image{img1}, vs, is, graphicsdriver.BlendCopy, dr, [graphics.ShaderSrcImageCount]image.Rectangle{}, atlas.NearestFilterShader, nil, graphicsdriver.FillRuleFillAll)
|
||||
|
||||
// Get the difference of the number of backends before and after the images are deallocated.
|
||||
c := atlas.BackendCountForTesting()
|
||||
img0.Deallocate()
|
||||
img1.Deallocate()
|
||||
|
||||
diff := c - atlas.BackendCountForTesting()
|
||||
if got, want := diff, 2; got != want {
|
||||
t.Errorf("got: %d, want: %d", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add tests to extend image on an atlas out of the main loop
|
||||
|
Loading…
Reference in New Issue
Block a user