unoplatform/uno · critical · Exception
{type} compile failed: {infoLog}
Error message
{type} compile failed: {infoLog} What it means
CompileShader in PixelBuffersGlCanvasElement throws when gl.GetShader(CompileStatus) returns non-True, meaning the GLSL compiler rejected the stage. The info log is appended so the syntax/driver error is visible. This is distinct from link failure (error 83) — it fires per-stage before the program is even created.
Source
Thrown at src/SamplesApp/SamplesApp.Samples/Windows_UI_Composition/PixelBuffersGlCanvasElement.cs:246
{
throw new Exception("Program link failed: " + gl.GetProgramInfoLog(prog));
}
gl.DetachShader(prog, vs);
gl.DetachShader(prog, fs);
gl.DeleteShader(vs);
gl.DeleteShader(fs);
return prog;
}
private static uint CompileShader(GL gl, ShaderType type, string source)
{
var sh = gl.CreateShader(type);
gl.ShaderSource(sh, source);
gl.CompileShader(sh);
gl.GetShader(sh, ShaderParameterName.CompileStatus, out int status);
if (status != (int)GLEnum.True)
{
throw new Exception($"{type} compile failed: " + gl.GetShaderInfoLog(sh));
}
return sh;
}
}
}
#endif
View on GitHub (pinned to 0418340488)
Solutions
- Read the appended infoLog — GLSL compiler errors cite a line number and the exact token at fault.
- Confirm the versionDef detection: print gl.GetStringS(StringName.ShadingLanguageVersion) and ensure the chosen `#version` directive actually matches the context (GLES contexts report 'OpenGL ES', others use desktop).
- If the context is WebGL1/GLES2 (no `#version 300 es`), rewrite the shaders to GLSL ES 1.00 (use gl_FragColor, no layout qualifiers, no in/out — use attribute/varying).
- Move `precision highp float;` to fragment-only on GLES contexts that reject it in the vertex stage, or downgrade to mediump where highp is unavailable.
- Validate with a reference compiler (e.g. Khronos reference glslang) offline to catch syntax errors before runtime.
Example fix
// before
if (status != (int)GLEnum.True)
throw new Exception($"{type} compile failed: " + gl.GetShaderInfoLog(sh));
// after — include source line numbers in the message for faster diagnosis
if (status != (int)GLEnum.True)
{
var log = gl.GetShaderInfoLog(sh);
var numbered = string.Join('\n', source.Split('\n').Select((l, i) => $"{i+1}: {l}"));
throw new Exception($"{type} compile failed: {log}\n--- source ---\n{numbered}");
} Defensive patterns
Strategy: validation
Validate before calling
// Validate the GLSL version is supported before compiling
var sl = gl.GetStringS(StringName.ShadingLanguageVersion);
var wantsGles = sl.Contains("OpenGL ES", StringComparison.OrdinalIgnoreCase);
if (wantsGles && !sl.Contains("3.")) return; // cannot compile #version 300 es here
// Pre-flight: confirm the source starts with the matching version directive
if (!source.StartsWith(wantsGles ? "#version 300 es" : "#version 330")) return; Try / catch
try { sh = CompileShader(gl, type, source); }
catch (Exception ex) when (ex.Message.Contains("compile failed"))
{
App.MainWindow?.LogError($"{type} compile failed: {ex.Message}");
sh = 0;
} Prevention
- Read ShadingLanguageVersion and pick the matching #version directive.
- Move `precision` declarations to the fragment stage on contexts that reject them in the vertex stage.
- Use GLSL ES 1.00 syntax for WebGL1/GLES2 contexts (no layout qualifiers, no in/out).
- Validate shader source offline with glslangValidator before runtime.
When it happens
Trigger: Inside CompileShader: gl.CreateShader(type) -> gl.ShaderSource -> gl.CompileShader -> gl.GetShader(CompileStatus) != True (lines 240-246). The vertex source is `#version 300 es` or `#version 330` followed by precision highp float, layout(location=0) in vec2 aPos, etc.
Common situations: The versionDef detection picked the wrong profile (e.g. desktop `#version 330` selected on a GLES-only context, or `#version 300 es` on WebGL1); `precision highp float` not supported on the vertex stage of a low-end GLES context (some require mediump); layout(location=X) syntax unsupported on GLSL < 330 / GLES < 300; a typo in an identifier that the compiler flags; WebGL rejects `gl_FragColor`-style reserved writes under core profile.
Related errors
- {type} compile failed: {infoLog}
- {type} compile failed: {infoLog}
- Error compiling shader of type {type}, failed with error {in
- {name} uniform not found on shader.
- Program link failed: {infoLog}
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/2154b80c46175aa6.
Report an issue: GitHub.