mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +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()
|
defer deferredM.Unlock()
|
||||||
return len(deferred)
|
return len(deferred)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BackendCountForTesting() int {
|
||||||
|
backendsM.Lock()
|
||||||
|
defer backendsM.Unlock()
|
||||||
|
return len(theBackends)
|
||||||
|
}
|
||||||
|
@ -689,18 +689,14 @@ func (i *Image) deallocate() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !i.isOnAtlas() {
|
if i.isOnAtlas() {
|
||||||
i.backend.image.Dispose()
|
i.backend.page.Free(i.node)
|
||||||
i.backend.image = nil
|
if !i.backend.page.IsEmpty() {
|
||||||
return
|
// As this part can be reused, this should be cleared explicitly.
|
||||||
}
|
r := i.regionWithPadding()
|
||||||
|
i.backend.clearPixels(r)
|
||||||
i.backend.page.Free(i.node)
|
return
|
||||||
if !i.backend.page.IsEmpty() {
|
}
|
||||||
// As this part can be reused, this should be cleared explicitly.
|
|
||||||
r := i.regionWithPadding()
|
|
||||||
i.backend.clearPixels(r)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
i.backend.image.Dispose()
|
i.backend.image.Dispose()
|
||||||
|
@ -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
|
// TODO: Add tests to extend image on an atlas out of the main loop
|
||||||
|
Loading…
Reference in New Issue
Block a user