unoplatform/uno · error · Exception

Fragment shader failed to compile: {infoLog}

Error message

Fragment shader failed to compile: {infoLog}

What it means

Sibling of the vertex-shader check: thrown when the fragment shader's CompileStatus is not True. The fragment source uses the same versionDef and a 'precision highp float' line plus 'in vec4 vertexColor', so it fails for the same driver/version reasons, plus stage-specific issues (varying/in qualifier mismatch, unsupported precision in the fragment stage).

Source

Thrown at src/SamplesApp/SamplesApp.Samples/Windows_UI_Composition/SimpleTriangleGlCanvasElement.cs:89

			uint vertexShader = gl.CreateShader(ShaderType.VertexShader);
			gl.ShaderSource(vertexShader, vertexCode);
			gl.CompileShader(vertexShader);

			gl.GetShader(vertexShader, ShaderParameterName.CompileStatus, out int vStatus);
			if (vStatus != (int)GLEnum.True)
			{
				throw new Exception("Vertex shader failed to compile: " + gl.GetShaderInfoLog(vertexShader));
			}

			uint fragmentShader = gl.CreateShader(ShaderType.FragmentShader);
			gl.ShaderSource(fragmentShader, fragmentCode);
			gl.CompileShader(fragmentShader);

			gl.GetShader(fragmentShader, ShaderParameterName.CompileStatus, out int fStatus);
			if (fStatus != (int)GLEnum.True)
			{
				throw new Exception("Fragment shader failed to compile: " + gl.GetShaderInfoLog(fragmentShader));
			}

			_program = gl.CreateProgram();
			gl.AttachShader(_program, vertexShader);
			gl.AttachShader(_program, fragmentShader);
			gl.LinkProgram(_program);

			gl.GetProgram(_program, ProgramPropertyARB.LinkStatus, out int lStatus);
			if (lStatus != (int)GLEnum.True)
			{
				throw new Exception("Program failed to link: " + gl.GetProgramInfoLog(_program));
			}

			gl.DetachShader(_program, vertexShader);
			gl.DetachShader(_program, fragmentShader);
			gl.DeleteShader(vertexShader);
			gl.DeleteShader(fragmentShader);
		}

View on GitHub (pinned to 0418340488)

Solutions

  1. Read the info log in the message to get the exact fragment-shader line/error.
  2. Replace 'precision highp float;' with 'precision mediump float;' — highp is optional in the fragment stage on many GLES devices.
  3. Confirm versionDef is correct for the context (see vertex-shader error); an ES context forced to '#version 330' fails here too.
  4. Verify the context is GLES 3.0 / GL 3.3 so 'in vec4 vertexColor' and '#version 300 es' are valid.
  5. On headless Linux, provide a working GL context (software rasterizer or GPU passthrough).

Example fix

// before
precision highp float; // for OpenGL ES compatibility
// after - use mediump which is guaranteed in the fragment stage
precision mediump float;
Defensive patterns

Strategy: validation

Validate before calling

// Fragment stage highp is optional; validate capability
int range[2], precision;
gl.GetShaderPrecisionFormat(ShaderType.FragmentShader, ShaderParameterName.HighFloat, out range[0], out range[1], out precision);
bool highpFrag = precision > 0;
var fragHeader = highpFrag ? "precision highp float;" : "precision mediump float;";

Try / catch

try { gl.CompileShader(fragmentShader); }
catch (Exception ex) when (ex.Message.Contains("Fragment shader failed to compile"))
{
    _log.Error($"Fragment GLSL compile failed: {ex.Message}");
}

Prevention

When it happens

Trigger: gl.CompileShader on the fragment shader on a context where the fragment GLSL is invalid: e.g. 'highp' not supported in fragment stage on older GLES2 hardware, the versionDef is '#version 330' while the context is ES, or 'in' is rejected because the context is pre-3.00.

Common situations: Same Skia GL host as the vertex error but it surfaces here because fragment-stage highp is the stricter constraint; mobile/low-end GPUs that advertise ES 2.0 only; a driver bug where the vertex shader compiles but the fragment does not due to precision limits.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/9817b9af80e364fc. Report an issue: GitHub.