stride3d/stride · critical · Exception
{cross.ContextCreate(&context)} : Could not create spirv con
Error message
{cross.ContextCreate(&context)} : Could not create spirv context What it means
SpirvTranslator.GetEntryPoints first creates a SPIRV-Cross context via cross.ContextCreate. If the native call does not return Result.Success, the translator throws with the raw result code and "Could not create spirv context". This is a native library initialization failure — no SPIR-V has been parsed yet, so the problem is with creating the cross-compilation context itself (native state, memory, or bad library initialization).
Solutions
- Verify the native SPIRV-Cross library for your platform/architecture ships with the app (correct runtime identifier folder).
- Note the numeric Result code in the message and check it against SPIRV-Cross error codes (OOM vs initialization failure).
- Reinstall/repair the package that carries the native binaries; ensure no old incompatible version is loaded from PATH.
- If transient OOM, reduce concurrent translators or free memory and retry.
Example fix
// before: native deps missing on linux-x64 deployment translator.GetEntryPoints(); // throws 'Could not create spirv context' // after: ensure runtimes/linux-x64/native/libspirv-cross.so is deployed next to the app translator.GetEntryPoints();
Defensive patterns
Strategy: try-catch
Validate before calling
// verify native library loads before translation
try { _ = NativeLibrary.Load("spirv-cross"); }
catch (DllNotFoundException) { EnsureNativeAssetsDeployed(); } Try / catch
try { var eps = translator.GetEntryPoints(); }
catch (Exception ex) when (ex.Message.Contains("Could not create spirv context")) {
throw new InvalidOperationException(
"Native SPIRV-Cross failed to init — check native binaries/Result code in message", ex);
} Prevention
- Ship native SPIRV-Cross binaries for every RID you deploy.
- Run a smoke translation at startup to fail fast on missing native deps.
- Log and map the numeric Result code in the message to a diagnosis.
When it happens
Trigger: Calling GetEntryPoints (or any translation entry) when the native SPIRV-Cross library fails to allocate/initialize its context — e.g. native DLL not properly loaded/initialized, incompatible native build, or OOM. The thrown message embeds the numeric Result returned by ContextCreate.
Common situations: Missing or mismatched native spirv-cross binary for the platform; running on an architecture without the native dependency; corrupted deployment of native assets.
Related errors
- spirv_to_dxil_pipeline failed; SPIR-V dumped to {dumpPath} {
- {cross.ContextParseSpirv(context, w, (nuint)Words.Length, &i
- Could not locate native executable ${executableName}
- Could not locate native library ${libraryName}
- Failed to initialize FreeType library (error {err})
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/2b115c7091c586af.
Report an issue: GitHub.
Appendix: source
Thrown at sources/shaders/Stride.Shaders.Compilers/SpirvTranslator.cs:32
public unsafe record struct SpirvTranslator(ReadOnlyMemory<uint> Words)
{
static readonly Cross cross;
static readonly Logger Log = GlobalLogger.GetLogger("SpirvTranslator");
static SpirvTranslator()
{
NativeLibraryHelper.PreloadLibrary("spirv-cross", typeof(SpirvTranslator));
cross = Cross.GetApi();
}
public List<(string RealName, string TranslatedName, ExecutionModel ExecutionModel)> GetEntryPoints(Backend backend = Backend.Hlsl)
{
Context* context = null;
ParsedIr* ir = null;
Compiler* compiler = null;
if (cross.ContextCreate(&context) != Result.Success)
throw new Exception($"{cross.ContextCreate(&context)} : Could not create spirv context");
fixed (uint* w = Words.Span)
if (cross.ContextParseSpirv(context, w, (nuint)Words.Length, &ir) != Result.Success)
throw new Exception($"{cross.ContextParseSpirv(context, w, (nuint)Words.Length, &ir)} : Could not parse spirv");
cross.ContextSetErrorCallback(context, new((void* userData, byte* errorData) =>
{
var error = Marshal.PtrToStringAnsi((IntPtr)errorData);
if (error != null)
Log.Error(error);
}), null);
if (cross.ContextCreateCompiler(context, backend, ir, CaptureMode.Copy, &compiler) != Result.Success)
throw new Exception($"{cross.ContextCreateCompiler(context, backend, ir, CaptureMode.Copy, &compiler)} : could not create compiler");
var result = new List<(string RealName, string TranslatedName, ExecutionModel ExecutionModel)>();
EntryPoint* entry_points = null;
nuint num_entry_points = 0;
cross.CompilerGetEntryPoints(compiler, &entry_points, &num_entry_points);View on GitHub (pinned to 96fad776d2)