From 23f710910fc724d937dad495d62abec3624d3fb0 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sat, 2 Jan 2021 18:28:41 +0100 Subject: [PATCH] gpu: reclaim stale images in atlas texture before resizing Issue found by Anthony Starks. Signed-off-by: Elias Naur --- gpu/compute.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gpu/compute.go b/gpu/compute.go index 4f2ecd28..2df1dfa2 100644 --- a/gpu/compute.go +++ b/gpu/compute.go @@ -267,6 +267,7 @@ func (g *compute) uploadImages(ops []imageOp) error { a := &g.atlas var uploads map[interface{}]*image.RGBA resize := false + reclaimed := false restart: for { for _, op := range ops { @@ -284,12 +285,19 @@ restart: a.positions = nil uploads = nil a.packer = packer{ - maxDim: maxDim + 256, + maxDim: maxDim, } - if maxDim > g.maxTextureDim { - return errors.New("compute: no space left in atlas texture") + if !reclaimed { + // Some images may no longer be in use, try again + // after clearing existing maps. + reclaimed = true + } else { + a.packer.maxDim += 256 + resize = true + if a.packer.maxDim > g.maxTextureDim { + return errors.New("compute: no space left in atlas texture") + } } - resize = true a.packer.newPage() continue restart }