{"record":{"id":"9a25f8801b5814a8","repo":"stride3d/stride","slug":"shader-name-could-not-be-compiled","errorCode":null,"errorMessage":"Shader {name} could not be compiled","messagePattern":"Shader (.+?) could not be compiled","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Compilers/ShaderLoaderBase.cs","lineNumber":73,"sourceCode":"        // Coordinate parallel compilations: only one thread compiles a given (name, macros) pair.\n        var macrosHash = ComputeMacrosHash(defines);\n        var macrosArray = defines.ToArray();\n        var key = (name, macrosHash);\n\n        var lazy = compilingShaders.GetOrAdd(key, _ => new Lazy<(ShaderBuffers, ObjectId)>(() =>\n        {\n            // Double-check cache (another thread may have finished between our check and this factory)\n            if (Cache.TryLoadFromCache(name, null, macrosArray, out var buf, out var h) && ValidateCachedHashes(buf))\n                return (buf, h);\n\n            if (!ExternalFileExists(name))\n                throw new InvalidOperationException($\"Shader {name} could not be found\");\n\n            if (!LoadExternalFileContent(name, out var filename, out var code, out h))\n                throw new InvalidOperationException($\"Shader {name} could not be loaded\");\n\n            if (!LoadFromCode(filename, code, h, macrosArray, out buf))\n                throw new InvalidOperationException($\"Shader {name} could not be compiled\");\n\n            return (buf, h);\n        }, LazyThreadSafetyMode.ExecutionAndPublication));\n\n        try\n        {\n            var result = lazy.Value;\n            buffer = result.Buffer;\n            hash = result.Hash;\n            isFromCache = false;\n            return true;\n        }\n        finally\n        {\n            compilingShaders.TryRemove(key, out _);\n        }\n    }\n","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Compilers/ShaderLoaderBase.cs#L55-L91","documentation":"Final stage of the lazy factory in ShaderLoaderBase.LoadExternalBuffer: the file exists and was read, but LoadFromCode(filename, code, h, macrosArray, out buf) returned false, meaning the SDSLC compilation pipeline did not produce a bytecode buffer. The loader throws \"Shader {name} could not be compiled\". In this overload no ILogger is attached, so the compiler's detailed errors were not rethrown and only this summary surfaces.","triggerScenarios":"Calling LoadExternalBuffer(name, defines, ...) where the .sdsl source has a compile error (syntax, unknown keyword, bad composition), or the compiler returned false for an internal reason, and no logger was set on the loader.","commonSituations":"SDSL syntax errors after editing a shader; incompatibility with macro combinations producing invalid code; shader using features the compiler version does not support.","solutions":["Attach a LoggerResult (set Log on the loader) so compile errors are captured and can be inspected instead of only getting the generic message.","Fix the SSDL/SDSL compile errors reported in the logger output for that shader source.","Test the shader with the failing macro combination in isolation to pinpoint which define breaks compilation.","Check the compiler version matches what produced other shaders (feature drift)."],"exampleFix":"// before\nvar loader = new ShaderLoaderBase(...); // no Log -> only generic throw\n// after\nvar log = new LoggerResult();\nloader.Log = log;\ntry { loader.LoadExternalBuffer(\"MyShader\", macros, out var buf, out var h, out var cached); }\ncatch (InvalidOperationException) { DumpErrors(log); }","handlingStrategy":"try-catch","validationCode":"// no cheap pre-check exists; attach a logger and validate source separately\nvar log = new LoggerResult();\nloader.Log = log;","typeGuard":null,"tryCatchPattern":"try { loader.LoadExternalBuffer(name, macros, out var buf, out var h, out var cached); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"could not be compiled\")) {\n    foreach (var m in log.Messages.Where(m => m.Type >= LogMessageType.Error))\n        Console.Error.WriteLine(m);\n}","preventionTips":["Always set loader.Log before loading so compiler diagnostics are captured.","Compile shaders in CI to catch SDSL regressions before runtime.","Test each macro combination used by effects against the compiler."],"tags":["shader","compilation-failed","shader-loader"],"backgroundTag":"compilation-failed","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}