{"record":{"id":"4c5a88a615d783dc","repo":"unoplatform/uno","slug":"error-compiling-shader-of-type-type-failed-with","errorCode":null,"errorMessage":"Error compiling shader of type {type}, failed with error {infoLog}","messagePattern":"Error compiling shader of type (.+?), failed with error (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/SamplesApp/SamplesApp.Samples/Windows_UI_Composition/RotatingCubeGlCanvasElement.cs","lineNumber":239,"sourceCode":"\t\t\t\t\tthrow new Exception($\"{name} uniform not found on shader.\");\n\t\t\t\t}\n\t\t\t\t_gl.Uniform1(location, value);\n\t\t\t}\n\n\t\t\tpublic void Dispose()\n\t\t\t{\n\t\t\t\t_gl.DeleteProgram(_handle);\n\t\t\t}\n\n\t\t\tprivate uint LoadShader(ShaderType type, string src)\n\t\t\t{\n\t\t\t\tuint handle = _gl.CreateShader(type);\n\t\t\t\t_gl.ShaderSource(handle, src);\n\t\t\t\t_gl.CompileShader(handle);\n\t\t\t\tstring infoLog = _gl.GetShaderInfoLog(handle);\n\t\t\t\tif (!string.IsNullOrWhiteSpace(infoLog))\n\t\t\t\t{\n\t\t\t\t\tthrow new Exception($\"Error compiling shader of type {type}, failed with error {infoLog}\");\n\t\t\t\t}\n\n\t\t\t\treturn handle;\n\t\t\t}\n\t\t}\n\n\t\tpublic class BufferObject<TDataType> : IDisposable where TDataType : unmanaged\n\t\t{\n\t\t\tprivate readonly uint _handle;\n\t\t\tprivate readonly BufferTargetARB _bufferType;\n\t\t\tprivate readonly GL _gl;\n\n\t\t\tpublic unsafe BufferObject(GL gl, Span<TDataType> data, BufferTargetARB bufferType)\n\t\t\t{\n\t\t\t\t_gl = gl;\n\t\t\t\t_bufferType = bufferType;\n\n\t\t\t\t_handle = _gl.GenBuffer();","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SamplesApp/SamplesApp.Samples/Windows_UI_Composition/RotatingCubeGlCanvasElement.cs#L221-L257","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check CompileStatus explicitly instead of info-log emptiness — the canonical pattern is GetShader(CompileStatus) != True ⇒ error; warnings are advisory.","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.","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.","Run the shader through glslangValidator offline to see whether the messages are warnings or errors.","Log the info log unconditionally for diagnostics but gate the throw on CompileStatus."],"exampleFix":"// before — throws on any non-empty log, including benign warnings\nstring infoLog = _gl.GetShaderInfoLog(handle);\nif (!string.IsNullOrWhiteSpace(infoLog))\n    throw new Exception($\"Error compiling shader of type {type}, failed with error {infoLog}\");\n\n// after — gate on compile status, log warnings separately\n_gl.GetShader(handle, ShaderParameterName.CompileStatus, out int status);\nvar infoLog = _gl.GetShaderInfoLog(handle);\nif (!string.IsNullOrWhiteSpace(infoLog))\n    System.Diagnostics.Debug.WriteLine($\"{type} shader diagnostics: {infoLog}\");\nif (status != (int)GLEnum.True)\n    throw new Exception($\"{type} shader failed to compile: {infoLog}\");","handlingStrategy":"validation","validationCode":"// Gate on CompileStatus, not on info-log emptiness — warnings are advisory\n_gl.GetShader(handle, ShaderParameterName.CompileStatus, out int status);\nvar infoLog = _gl.GetShaderInfoLog(handle);\nif (!string.IsNullOrWhiteSpace(infoLog))\n    System.Diagnostics.Debug.WriteLine($\"{type} shader diagnostics: {infoLog}\");\nif (status != (int)GLEnum.True)\n    throw new Exception($\"{type} shader failed to compile: {infoLog}\");","typeGuard":null,"tryCatchPattern":"try { uint handle = LoadShader(type, src); }\ncatch (Exception ex) when (ex.Message.Contains(\"Error compiling shader\"))\n{\n    // Distinguish compile failure from spurious warning-triggered throw\n    App.MainWindow?.LogError($\"Shader {type}: {ex.Message}\");\n    handle = 0;\n}","preventionTips":["Check CompileStatus explicitly — never key the throw on info-log emptiness, since drivers emit benign warnings.","Log the info log unconditionally for diagnostics, but only throw on CompileStatus == False.","Drop `precision highp float;` from desktop (#version 330) shaders to avoid ignored-precision warnings.","Validate shader source offline with glslangValidator to separate warnings from errors."],"tags":["opengl","silk-net","glsl","shader-compile","diagnostics","shader","false-positive"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}