stride3d/stride · error · ObjectDisposedException
EffectSystem has been disposed. This Effect compilation has…
Error message
EffectSystem has been disposed. This Effect compilation has been cancelled.
What it means
EffectSystem.CreateEffect aborts with ObjectDisposedException if the system was disposed while an effect compilation was in flight. The isInitialized check under the cachedEffects lock detects shutdown that happened during asynchronous compilation.
Solutions
- Ensure all LoadEffect calls complete before disposing the GraphicsDevice/EffectSystem.
- Await pending effect compilation tasks before shutdown.
- Recreate the EffectSystem (re-initialize) if you need to load effects after disposal.
- Guard application shutdown order: release materials/effects first, then the device.
Example fix
// before
device.Dispose();
var effect = effectSystem.LoadEffect("MyEffect"); // throws
// after
await loadTask; // finish compilations
effectSystem.Dispose();
device.Dispose(); Defensive patterns
Strategy: try-catch
Validate before calling
// Check before requesting an effect
if (!effectSystem.IsInitialized) throw new InvalidOperationException("EffectSystem disposed; cannot load effects"); Type guard
bool CanLoadEffects(EffectSystem s) => s != null && s.IsInitialized;
Try / catch
try { var effect = effectSystem.LoadEffect("MyEffect"); }
catch (ObjectDisposedException)
{
// EffectSystem was disposed mid-compilation; re-initialize or abort the load
} Prevention
- Await all LoadEffect tasks before disposing GraphicsDevice.
- Order shutdown: cancel loads -> dispose effects/materials -> dispose device.
- Avoid fire-and-forget scene loads during window close.
When it happens
Trigger: Calling LoadEffect (or awaiting a pending effect task) after GraphicsDevice/EffectSystem was disposed, e.g. during scene teardown or application shutdown while shaders still compile in the background.
Common situations: Loading scenes/materials asynchronously and disposing the device when a window closes; race between background compilation and Dispose.
Related errors
- This controller is beeing disposed.
- Custom strides is not supported with packed PixelFormats
- Could not compile shader. See error messages:
- EffectCompiler returned no shader and no compilation error.
- Unable to find the base
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/869eac2172f751c5.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Rendering/Rendering/EffectSystem.cs:188
}
// TODO: THIS IS JUST A WORKAROUND, REMOVE THIS
private static void CheckResult(LoggerResult compilerResult)
{
if (compilerResult.HasErrors)
{
throw new InvalidOperationException("Could not compile shader. See error messages: " + compilerResult.ToText());
}
}
private Effect CreateEffect(string effectName, EffectBytecodeCompilerResult effectBytecodeCompilerResult, CompilerResults compilerResult)
{
Effect effect;
lock (cachedEffects)
{
if (!isInitialized)
throw new ObjectDisposedException(nameof(EffectSystem), "EffectSystem has been disposed. This Effect compilation has been cancelled.");
if (effectBytecodeCompilerResult.CompilationLog.HasErrors)
{
// Unregister result
// TODO: Should we keep it so that failure never change?
if (earlyCompilerCache.TryGetValue(effectName, out List<CompilerResults> effectCompilerResults))
{
effectCompilerResults.Remove(compilerResult);
}
}
CheckResult(effectBytecodeCompilerResult.CompilationLog);
var bytecode = effectBytecodeCompilerResult.Bytecode
?? throw new InvalidOperationException("EffectCompiler returned no shader and no compilation error.");
if (!cachedEffects.TryGetValue(bytecode, out effect))
{View on GitHub (pinned to 96fad776d2)