diff --git a/internal/atlas/image.go b/internal/atlas/image.go index be134b5e8..97e8a9eb3 100644 --- a/internal/atlas/image.go +++ b/internal/atlas/image.go @@ -59,7 +59,7 @@ func temporaryPixelsByteSize(size int) int { // Be careful that the returned pixels might not be zero-cleared. func (t *temporaryPixels) alloc(size int) []byte { if len(t.pixels) < t.pos+size { - t.pixels = make([]byte, temporaryPixelsByteSize(t.pos+size)) + t.pixels = make([]byte, max(len(t.pixels)*2, temporaryPixelsByteSize(size))) t.pos = 0 } pix := t.pixels[t.pos : t.pos+size] diff --git a/internal/graphics/vertex.go b/internal/graphics/vertex.go index 8ea28fa5f..defb980d8 100644 --- a/internal/graphics/vertex.go +++ b/internal/graphics/vertex.go @@ -75,13 +75,20 @@ func verticesBackendFloat32Size(size int) int { return l } +func max(a, b int) int { + if a > b { + return a + } + return b +} + func (v *verticesBackend) slice(n int) []float32 { v.m.Lock() defer v.m.Unlock() need := n * VertexFloatNum if len(v.backend) < v.pos+need { - v.backend = make([]float32, verticesBackendFloat32Size(v.pos+need)) + v.backend = make([]float32, max(len(v.backend)*2, verticesBackendFloat32Size(need))) v.pos = 0 } s := v.backend[v.pos : v.pos+need]