Why is OpenTK's GL.GetShaderInfoLog returning an empty string when the shader has a syntax error?

21 views Asked by At

Here's my code:

        private static int CompileShader(ShaderType shaderType, string shaderCode, string shaderPath)
        {
            int shaderId = GL.CreateShader(shaderType);
            GL.ShaderSource(shaderId, shaderCode);
            GL.CompileShader(shaderId);
            string errorMessage = GL.GetShaderInfoLog(shaderId);
            if (errorMessage != String.Empty)
            {
                throw new Exception($"error while compiling {shaderPath}:\n{errorMessage}");
            }
            return shaderId;
        }

When I introduce a syntax error into my shader and set a breakpoint on the throw line, it doesn't hit that breakpoint. Instead, I get an error when it goes to try to link the shader program, and any compilation error message is lost / goes unreported.

Any idea why?

If I remove the syntax error, the shader compiles, links and works - I get the expected rendering.

Removing the breakpoint makes no difference, I just get the linker error.

Stepping through the function and checking the errorMessage value reveals that it is indeed an empty string even when the shader has a syntax error that prevents successful compilation.

0

There are 0 answers