From 3547d999b1c577d30c472b37072b1ff9b2e992e5 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 25 Aug 2024 11:45:54 +0900 Subject: [PATCH] internal/graphicsdriver/opengl/gl: bug fix: crash when log length is 0 --- internal/graphicsdriver/opengl/gl/default_cgo.go | 6 ++++++ internal/graphicsdriver/opengl/gl/default_purego.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/internal/graphicsdriver/opengl/gl/default_cgo.go b/internal/graphicsdriver/opengl/gl/default_cgo.go index 234f9a707..244b33ee0 100644 --- a/internal/graphicsdriver/opengl/gl/default_cgo.go +++ b/internal/graphicsdriver/opengl/gl/default_cgo.go @@ -592,6 +592,9 @@ func (c *defaultContext) GetInteger(pname uint32) int { func (c *defaultContext) GetProgramInfoLog(program uint32) string { bufSize := c.GetProgrami(program, INFO_LOG_LENGTH) + if bufSize == 0 { + return "" + } infoLog := make([]byte, bufSize) C.glowGetProgramInfoLog(c.gpGetProgramInfoLog, C.GLuint(program), C.GLsizei(bufSize), nil, (*C.GLchar)(unsafe.Pointer(&infoLog[0]))) return string(infoLog) @@ -605,6 +608,9 @@ func (c *defaultContext) GetProgrami(program uint32, pname uint32) int { func (c *defaultContext) GetShaderInfoLog(shader uint32) string { bufSize := c.GetShaderi(shader, INFO_LOG_LENGTH) + if bufSize == 0 { + return "" + } infoLog := make([]byte, bufSize) C.glowGetShaderInfoLog(c.gpGetShaderInfoLog, C.GLuint(shader), C.GLsizei(bufSize), nil, (*C.GLchar)(unsafe.Pointer(&infoLog[0]))) return string(infoLog) diff --git a/internal/graphicsdriver/opengl/gl/default_purego.go b/internal/graphicsdriver/opengl/gl/default_purego.go index 1e18d5730..05e65b570 100644 --- a/internal/graphicsdriver/opengl/gl/default_purego.go +++ b/internal/graphicsdriver/opengl/gl/default_purego.go @@ -300,6 +300,9 @@ func (c *defaultContext) GetInteger(pname uint32) int { func (c *defaultContext) GetProgramInfoLog(program uint32) string { bufSize := c.GetProgrami(program, INFO_LOG_LENGTH) + if bufSize == 0 { + return "" + } infoLog := make([]byte, bufSize) purego.SyscallN(c.gpGetProgramInfoLog, uintptr(program), uintptr(bufSize), 0, uintptr(unsafe.Pointer(&infoLog[0]))) return string(infoLog) @@ -313,6 +316,9 @@ func (c *defaultContext) GetProgrami(program uint32, pname uint32) int { func (c *defaultContext) GetShaderInfoLog(shader uint32) string { bufSize := c.GetShaderi(shader, INFO_LOG_LENGTH) + if bufSize == 0 { + return "" + } infoLog := make([]byte, bufSize) purego.SyscallN(c.gpGetShaderInfoLog, uintptr(shader), uintptr(bufSize), 0, uintptr(unsafe.Pointer(&infoLog[0]))) return string(infoLog)