diff --git a/image.go b/image.go index f649b1243..8935987c1 100644 --- a/image.go +++ b/image.go @@ -38,10 +38,10 @@ type Image struct { original *Image bounds image.Rectangle - // tmpVertices must not be reused until the vertices are sent to the graphics command queue. + // tmpVertices must not be reused until ui.Image.Draw* is called. tmpVertices []float32 - // tmpUniforms must not be reused until the vertices are sent to the graphics command queue. + // tmpUniforms must not be reused until ui.Image.Draw* is called. tmpUniforms []uint32 // Do not add a 'buffering' member that are resolved lazily. diff --git a/internal/graphicscommand/command.go b/internal/graphicscommand/command.go index 09dd2fb18..40cf714e7 100644 --- a/internal/graphicscommand/command.go +++ b/internal/graphicscommand/command.go @@ -110,6 +110,9 @@ func (q *commandQueue) EnqueueDrawTrianglesCommand(dst *Image, srcs [graphics.Sh q.tmpNumVertexFloats += len(vertices) q.tmpNumIndices += len(indices) + // prependPreservedUniforms not only prepends values to the given slice but also creates a new slice. + // Allocating a new slice is necessary to make EnqueueDrawTrianglesCommand safe so far. + // TODO: This might cause a performance issue (#2601). uniforms = q.prependPreservedUniforms(uniforms, shader, dst, srcs, offsets, dstRegion, srcRegion) // Remove unused uniform variables so that more commands can be merged.