{"record":{"id":"4e3d1428b2f02bf5","repo":"stride3d/stride","slug":"cross-contextcreatecompiler-context-backend-ir-capturemode","errorCode":null,"errorMessage":"{cross.ContextCreateCompiler(context, backend, ir, CaptureMode.Copy, &compiler)} : could not create compiler","messagePattern":"(.+?) : could not create compiler","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Compilers/SpirvTranslator.cs","lineNumber":45,"sourceCode":"    {\n        Context* context = null;\n        ParsedIr* ir = null;\n        Compiler* compiler = null;\n        if (cross.ContextCreate(&context) != Result.Success)\n            throw new Exception($\"{cross.ContextCreate(&context)} : Could not create spirv context\");\n        fixed (uint* w = Words.Span)\n            if (cross.ContextParseSpirv(context, w, (nuint)Words.Length, &ir) != Result.Success)\n                throw new Exception($\"{cross.ContextParseSpirv(context, w, (nuint)Words.Length, &ir)} : Could not parse spirv\");\n\n        cross.ContextSetErrorCallback(context, new((void* userData, byte* errorData) =>\n        {\n            var error = Marshal.PtrToStringAnsi((IntPtr)errorData);\n            if (error != null)\n                Log.Error(error);\n        }), null);\n\n        if (cross.ContextCreateCompiler(context, backend, ir, CaptureMode.Copy, &compiler) != Result.Success)\n            throw new Exception($\"{cross.ContextCreateCompiler(context, backend, ir, CaptureMode.Copy, &compiler)} : could not create compiler\");\n\n        var result = new List<(string RealName, string TranslatedName, ExecutionModel ExecutionModel)>();\n        EntryPoint* entry_points = null;\n        nuint num_entry_points = 0;\n        cross.CompilerGetEntryPoints(compiler, &entry_points, &num_entry_points);\n        for (int i = 0; i < (int)num_entry_points; ++i)\n        {\n            var entryPointModel = entry_points[i].ExecutionModel;\n            var entryPointName = Marshal.PtrToStringAnsi((IntPtr)entry_points[i].Name)!;\n            result.Add((entryPointName, \"main\", entryPointModel));\n        }\n\n        cross.ContextReleaseAllocations(context);\n        cross.ContextDestroy(context);\n\n        return result;\n    }\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Compilers/SpirvTranslator.cs#L27-L63","documentation":"SpirvTranslator.GetEntryPoints throws this when the native spirv-cross call ContextCreateCompiler fails to instantiate a compiler object for the requested backend after successfully creating a context and parsing the SPIR-V. The exception message embeds the non-success Result code returned by the native library. It means the parsed IR could not be handed to a backend compiler (HLSL/GLSL/etc.).","triggerScenarios":"Calling GetEntryPoints(backend) when spirv-cross rejects ContextCreateCompiler: invalid/unsupported Backend enum value for the loaded spirv-cross build, corrupt or feature-inappropriate parsed IR, or the context/IR was in an invalid state (e.g. empty or zero-length Words parsed into a degenerate IR).","commonSituations":"Using a Backend value not compiled into the bundled spirv-cross native library; a mismatched spirv-cross native binary that rejects the capture mode or IR; passing SPIR-V whose parse produced a degenerate module; running on a platform where the preloaded spirv-cross native lib is an incompatible version.","solutions":["Verify the Backend argument is a value supported by the bundled spirv-cross (Hlsl, Glsl, Msl) and matches how the SPIR-V was produced","Check the error callback log lines emitted just before the throw — spirv-cross usually logs the concrete reason via ContextSetErrorCallback","Validate the SPIR-V module with spirv-val to rule out corrupt/invalid IR","Ensure the preloaded 'spirv-cross' native library matches the Silk.NET.SPIRV.Cross API version (NativeLibraryHelper.PreloadLibrary in the static constructor)","Retry with the default Backend.Hlsl to isolate backend-specific failures"],"exampleFix":"// before\nvar entryPoints = translator.GetEntryPoints((Backend)42);\n// after\nif (!Enum.IsDefined(backend)) throw new ArgumentException($\"Unsupported backend {backend}\");\nvar entryPoints = translator.GetEntryPoints(backend);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(Backend), backend)) throw new ArgumentOutOfRangeException(nameof(backend), $\"Unsupported spirv-cross backend: {backend}\");","typeGuard":null,"tryCatchPattern":"try { var eps = translator.GetEntryPoints(backend); } catch (Exception ex) when (ex.Message.Contains(\"could not create compiler\")) { Log.Error($\"spirv-cross backend {backend} failed: {ex.Message}\"); throw; }","preventionTips":["Only pass Backend values known to be compiled into the bundled spirv-cross","Check the logger output from ContextSetErrorCallback for the native-side reason","Keep the native spirv-cross binary and Silk.NET.SPIRV.Cross bindings version-aligned","Validate SPIR-V with spirv-val before any translation"],"tags":["spirv-cross","native-interop","shader-compilation","backend"],"backgroundTag":"unsupported-enum-value","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"}