unoplatform/uno · error · Exception

Error compiling shader of type {type}, failed with error {in

Error message

Error compiling shader of type {type}, failed with error {infoLog}

What it means

The private LoadShader in RotatingCubeGlCanvasElement's Shader class throws if the shader info log is non-empty AFTER compiling. Unlike the other samples which check gl.GetShader(CompileStatus) for an explicit pass/fail, this implementation keys on GetShaderInfoLog content — so it throws not only on hard compile errors but also on benign warnings, which is over-strict and a latent bug. The info log can contain warnings even when compilation succeeded.

Source

Thrown at src/SamplesApp/SamplesApp.Samples/Windows_UI_Composition/RotatingCubeGlCanvasElement.cs:239

					throw new Exception($"{name} uniform not found on shader.");
				}
				_gl.Uniform1(location, value);
			}

			public void Dispose()
			{
				_gl.DeleteProgram(_handle);
			}

			private uint LoadShader(ShaderType type, string src)
			{
				uint handle = _gl.CreateShader(type);
				_gl.ShaderSource(handle, src);
				_gl.CompileShader(handle);
				string infoLog = _gl.GetShaderInfoLog(handle);
				if (!string.IsNullOrWhiteSpace(infoLog))
				{
					throw new Exception($"Error compiling shader of type {type}, failed with error {infoLog}");
				}

				return handle;
			}
		}

		public class BufferObject<TDataType> : IDisposable where TDataType : unmanaged
		{
			private readonly uint _handle;
			private readonly BufferTargetARB _bufferType;
			private readonly GL _gl;

			public unsafe BufferObject(GL gl, Span<TDataType> data, BufferTargetARB bufferType)
			{
				_gl = gl;
				_bufferType = bufferType;

				_handle = _gl.GenBuffer();

View on GitHub (pinned to 0418340488)

Solutions

  1. Check CompileStatus explicitly instead of info-log emptiness — the canonical pattern is GetShader(CompileStatus) != True ⇒ error; warnings are advisory.
  2. If you want to surface warnings, separate them from errors: compile-status False ⇒ throw with log; compile-status True but log non-empty ⇒ log as warning, do not throw.
  3. Strip the `precision highp float;` line on desktop GL (#version 330) where it generates an ignored-precision warning, or keep it only for GLES contexts.
  4. Run the shader through glslangValidator offline to see whether the messages are warnings or errors.
  5. Log the info log unconditionally for diagnostics but gate the throw on CompileStatus.

Example fix

// before — throws on any non-empty log, including benign warnings
string infoLog = _gl.GetShaderInfoLog(handle);
if (!string.IsNullOrWhiteSpace(infoLog))
    throw new Exception($"Error compiling shader of type {type}, failed with error {infoLog}");

// after — gate on compile status, log warnings separately
_gl.GetShader(handle, ShaderParameterName.CompileStatus, out int status);
var infoLog = _gl.GetShaderInfoLog(handle);
if (!string.IsNullOrWhiteSpace(infoLog))
    System.Diagnostics.Debug.WriteLine($"{type} shader diagnostics: {infoLog}");
if (status != (int)GLEnum.True)
    throw new Exception($"{type} shader failed to compile: {infoLog}");
Defensive patterns

Strategy: validation

Validate before calling

// Gate on CompileStatus, not on info-log emptiness — warnings are advisory
_gl.GetShader(handle, ShaderParameterName.CompileStatus, out int status);
var infoLog = _gl.GetShaderInfoLog(handle);
if (!string.IsNullOrWhiteSpace(infoLog))
    System.Diagnostics.Debug.WriteLine($"{type} shader diagnostics: {infoLog}");
if (status != (int)GLEnum.True)
    throw new Exception($"{type} shader failed to compile: {infoLog}");

Try / catch

try { uint handle = LoadShader(type, src); }
catch (Exception ex) when (ex.Message.Contains("Error compiling shader"))
{
    // Distinguish compile failure from spurious warning-triggered throw
    App.MainWindow?.LogError($"Shader {type}: {ex.Message}");
    handle = 0;
}

Prevention

When it happens

Trigger: In LoadShader: CreateShader + ShaderSource + CompileShader + string infoLog = GetShaderInfoLog(handle); throw if !string.IsNullOrWhiteSpace(infoLog) (lines 231-239). This does NOT check CompileStatus — it treats any non-empty log as fatal.

Common situations: A GLSL warning (e.g. 'implicit cast from int to float', 'variable declared but never used', 'precision qualifier ignored on vertex shader') appears in the info log even though compilation succeeded → spurious throw; the versionDef prepend at line 111 produces a `#version` followed by `precision highp float` which some desktop drivers warn about ('precision statement ignored'); vendor drivers (NVIDIA) emit perf hints in the info log that are non-fatal but non-empty; a genuine compile error also populates the log and is correctly surfaced here, but indistinguishable from a warning.

Related errors


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