{"record":{"id":"2dcfa5a47774ab1b","repo":"unoplatform/uno","slug":"vertex-shader-failed-to-compile-infolog","errorCode":null,"errorMessage":"Vertex shader failed to compile: {infoLog}","messagePattern":"Vertex shader failed to compile: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/SamplesApp/SamplesApp.Samples/Windows_UI_Composition/SimpleTriangleGlCanvasElement.cs","lineNumber":79,"sourceCode":"\t\t\tprecision highp float; // for OpenGL ES compatibility\n\n\t\t\tout vec4 out_color;\n\t\t\tin vec4 vertexColor;\n\n\t\t\tvoid main()\n\t\t\t{\n\t\t\t\tout_color = vertexColor;\n\t\t\t}\n\t\t\t\"\"\";\n\n\t\t\tuint vertexShader = gl.CreateShader(ShaderType.VertexShader);\n\t\t\tgl.ShaderSource(vertexShader, vertexCode);\n\t\t\tgl.CompileShader(vertexShader);\n\n\t\t\tgl.GetShader(vertexShader, ShaderParameterName.CompileStatus, out int vStatus);\n\t\t\tif (vStatus != (int)GLEnum.True)\n\t\t\t{\n\t\t\t\tthrow new Exception(\"Vertex shader failed to compile: \" + gl.GetShaderInfoLog(vertexShader));\n\t\t\t}\n\n\t\t\tuint fragmentShader = gl.CreateShader(ShaderType.FragmentShader);\n\t\t\tgl.ShaderSource(fragmentShader, fragmentCode);\n\t\t\tgl.CompileShader(fragmentShader);\n\n\t\t\tgl.GetShader(fragmentShader, ShaderParameterName.CompileStatus, out int fStatus);\n\t\t\tif (fStatus != (int)GLEnum.True)\n\t\t\t{\n\t\t\t\tthrow new Exception(\"Fragment shader failed to compile: \" + gl.GetShaderInfoLog(fragmentShader));\n\t\t\t}\n\n\t\t\t_program = gl.CreateProgram();\n\t\t\tgl.AttachShader(_program, vertexShader);\n\t\t\tgl.AttachShader(_program, fragmentShader);\n\t\t\tgl.LinkProgram(_program);\n\n\t\t\tgl.GetProgram(_program, ProgramPropertyARB.LinkStatus, out int lStatus);","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SamplesApp/SamplesApp.Samples/Windows_UI_Composition/SimpleTriangleGlCanvasElement.cs#L61-L97","documentation":"Thrown by the SimpleTriangle OpenGL sample after the GL driver reports a vertex-shader compile failure. The code calls gl.CompileShader then gl.GetShader(CompileStatus); a status other than GLEnum.True triggers the throw, appending the driver's info log. It indicates the GLSL source the sample generated is syntactically or semantically invalid for the active GL/GLES context.","triggerScenarios":"Calling GLCanvasElement_SimpleTriangleElement.Init on a platform whose GL driver rejects the generated vertex shader. This happens specifically when the chosen versionDef ('#version 300 es' for OpenGL ES, '#version 330' otherwise) is wrong for the context, or when the 'precision highp float' line / 'layout (location=0)' qualifier is unsupported by the driver.","commonSituations":"Running the Skia GL sample on a machine whose GL context is actually desktop GL but reports an ES shading-language version (or vice versa); running on a VM/remote GPU with a limited GLSL ES profile; a driver that lacks highp in the fragment stage; GL context creation returning an unexpected version string so the versionDef branch picks the wrong directive.","solutions":["Read the full message: the appended info log names the exact GLSL line and error (e.g. 'ERROR: 0:1: '' : #version must be the first non-whitespace'). Fix the shader line it points at.","Verify the active context version (gl.GetStringS(StringName.Version) and StringName.ShadingLanguageVersion) and confirm versionDef matched it; flip '#version 300 es' to '#version 330' or vice versa if the branch mis-detected ES.","If the driver lacks highp, change 'precision highp float;' to 'precision mediump float;' or move the precision statement only where the stage requires it.","If 'layout (location=0)' is rejected, the context is pre-GLSL-1.30/GLES-1.00; ensure a 3.x core / GLES 3.0 context is created (Skia GL host configuration).","On headless/remote Linux, force a real GL context via LIBGL_ALWAYS_SOFTWARE=1 or a supported GPU passthrough so the driver reports a usable shading-language version."],"exampleFix":"// before (versionDef branch may mis-detect ES)\nvar versionDef = slVersion.Contains(\"OpenGL ES\", StringComparison.InvariantCultureIgnoreCase)\n    ? \"#version 300 es\"\n    : \"#version 330\";\n// after - log the detected versions so a mismatch is visible, and require GLES3 / GL3.3\n_log.Debug($\"GL={gl.GetStringS(StringName.Version)} GLSL={slVersion}\");\nif (!slVersion.StartsWith(\"3.30\") && !slVersion.Contains(\"OpenGL ES 3\"))\n{\n    throw new NotSupportedException($\"This sample needs GLSL 3.30 or GLES 3.00, got {slVersion}\");\n}","handlingStrategy":"validation","validationCode":"// Validate the GLSL version directive matches the context before compiling\nvar glVer = gl.GetStringS(StringName.Version);\nvar slVer = gl.GetStringS(StringName.ShadingLanguageVersion);\nbool isES = slVer.Contains(\"OpenGL ES\", StringComparison.InvariantCultureIgnoreCase);\nif (isES && !slVer.Contains(\"3.\")) throw new NotSupportedException($\"Need GLES 3.00 shading language, got {slVer}\");\nif (!isES && !slVer.StartsWith(\"3.30\")) throw new NotSupportedException($\"Need GLSL 3.30, got {slVer}\");","typeGuard":null,"tryCatchPattern":"try { gl.CompileShader(vertexShader); }\ncatch (Exception ex) when (ex.Message.Contains(\"Vertex shader failed to compile\"))\n{\n    _log.Error($\"GLSL compile failed (version={slVersion}): {ex.Message}\");\n    // fall back to a known-good minimal shader or disable the sample\n}","preventionTips":["Log the active GL + shading-language version at Init so version mismatch is visible before the throw.","Keep the version directive selection in one place and assert the branch taken.","On CI, run GL samples under a documented context (software rasterizer or known GPU)."],"tags":["opengl","glsl","shader","skia","graphics","samples"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}