From 7661147e318a17151104c2d704f639cf910f478f Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 31 Oct 2021 22:34:07 +0900 Subject: [PATCH] internal/graphicsdriver/opengl: Avoid allocations by escaping to heap --- internal/graphicsdriver/opengl/context_desktop.go | 4 +++- internal/graphicsdriver/opengl/context_mobile.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/graphicsdriver/opengl/context_desktop.go b/internal/graphicsdriver/opengl/context_desktop.go index 1aee657fe..7e518c2e9 100644 --- a/internal/graphicsdriver/opengl/context_desktop.go +++ b/internal/graphicsdriver/opengl/context_desktop.go @@ -418,7 +418,9 @@ func (c *context) uniformFloats(p program, location string, v []float32, typ sha case shaderir.Mat4: gl.UniformMatrix4fv(l, len, false, (*float32)(gl.Ptr(v))) default: - panic(fmt.Sprintf("opengl: unexpected type: %s", typ.String())) + // Copy shaderir.Type value to avoid heap allocation of typ. + t := typ + panic(fmt.Sprintf("opengl: unexpected type: %s", t.String())) } return true } diff --git a/internal/graphicsdriver/opengl/context_mobile.go b/internal/graphicsdriver/opengl/context_mobile.go index e74aa6fdf..74cbdbfbf 100644 --- a/internal/graphicsdriver/opengl/context_mobile.go +++ b/internal/graphicsdriver/opengl/context_mobile.go @@ -384,7 +384,9 @@ func (c *context) uniformFloats(p program, location string, v []float32, typ sha case shaderir.Mat4: c.ctx.UniformMatrix4fv(int32(l), false, v) default: - panic(fmt.Sprintf("opengl: unexpected type: %s", typ.String())) + // Copy shaderir.Type value to avoid heap allocation of typ. + t := typ + panic(fmt.Sprintf("opengl: unexpected type: %s", t.String())) } return true }