diff --git a/internal/graphicsdriver/metal/graphics_darwin.go b/internal/graphicsdriver/metal/graphics_darwin.go index 38a10b21a..8f07efc93 100644 --- a/internal/graphicsdriver/metal/graphics_darwin.go +++ b/internal/graphicsdriver/metal/graphics_darwin.go @@ -133,6 +133,10 @@ func (g *Graphics) SetUIView(uiview uintptr) { } func pow2(x uintptr) uintptr { + if x > (math.MaxUint+1)/2 { + return math.MaxUint + } + var p2 uintptr = 1 for p2 < x { p2 *= 2 diff --git a/internal/graphicsdriver/opengl/program.go b/internal/graphicsdriver/opengl/program.go index 19398e2d2..79276ce48 100644 --- a/internal/graphicsdriver/opengl/program.go +++ b/internal/graphicsdriver/opengl/program.go @@ -16,6 +16,7 @@ package opengl import ( "fmt" + "math" "runtime" "unsafe" @@ -157,6 +158,10 @@ func (s *openGLState) reset(context *context) error { } func pow2(x int) int { + if x > (math.MaxInt+1)/2 { + return math.MaxInt + } + p2 := 1 for p2 < x { p2 *= 2