internal/atlas: dispose images at ReadPixels

Without resolveDeferred() at ReadPixels, many images are never disposed
in tests.

Updates #2292
This commit is contained in:
Hajime Hoshi 2022-09-01 23:54:54 +09:00
parent 7fab62158d
commit cdf83ad2fc
2 changed files with 5 additions and 0 deletions

View File

@ -576,6 +576,10 @@ func (i *Image) ReadPixels(graphicsDriver graphicsdriver.Graphics, pixels []byte
backendsM.Lock()
defer backendsM.Unlock()
// In the tests, BeginFrame might not be called often and then images might not be disposed (#2292).
// To prevent memory leaks, resolve the deferred functions here.
resolveDeferred()
if i.backend == nil || i.backend.restorable == nil {
for i := range pixels {
pixels[i] = 0

View File

@ -778,6 +778,7 @@ func (g *Graphics) End(present bool) error {
if err := g.waitForCommandQueue(); err != nil {
return err
}
g.releaseResources(g.frameIndex)
g.releaseVerticesAndIndices(g.frameIndex)
}