stride3d/stride · error · ArgumentNullException
Cannot deep clone mixin
Error message
Cannot deep clone mixin [{Name}] from a null parent What it means
DeepCloneFrom throws an ArgumentNullException (with this message) when the parent ShaderMixinSource is null. Deep cloning additionally clones each child ShaderClassCode mixin individually, so it likewise requires a non-null source. Called by Compile during shader compilation preparation.
Solutions
- Ensure the shader family/mixins are registered in the shader source collection before Compile runs, so the parent passed to DeepCloneFrom is non-null.
- Add a null check before Compile: if the mixin source is null, log the missing shader name and fail early with a clear message.
- Inspect the effect compiler pipeline stage producing the null parent (breakpoint or log in DeepCloneFrom callers) and fix the resolution step.
Example fix
// before
var mixin = new ShaderMixinSource();
compiler.Compile(mixin); // internally DeepCloneFrom(null)
// after
var mixin = new ShaderMixinSource();
mixin.Mixins.Add((ShaderClassCode)ShaderManager.Find("MyShader")); // populate before compile
compiler.Compile(mixin); Defensive patterns
Strategy: type-guard
Validate before calling
if (parent == null || parent.Mixins.Count == 0)
throw new InvalidOperationException("Compile requires an initialized, non-null mixin source"); Type guard
bool TryDeepClone(ShaderMixinSource target, ShaderMixinSource? parent)
{
if (parent is null) return false;
target.DeepCloneFrom(parent);
return true;
} Try / catch
try { mixin.DeepCloneFrom(parent); compiler.Compile(...); }
catch (ArgumentNullException ex) when (ex.ParamName == "parent")
{
// trace which compile stage passed a null mixin source and fix registration
} Prevention
- Register shader families before invoking Compile on effects that reference them.
- Assert the mixin source is populated (Mixins.Count > 0) in test fixtures before compiling.
- Add compiler-pass logging so a null parent can be traced to the resolution stage that produced it.
When it happens
Trigger: ShaderMixinSource.DeepCloneFrom(null) reached from Compile when the mixin source that Compile resolved (via a shader manager or effect compiler pass) was null — e.g. a requested shader family was never registered or was filtered out by the compiler.
Common situations: Compiling an effect whose ShaderSource was never attached/registered; a compiler pass (e.g. effect permutation resolution) yielding null for the mixin; tests that build a ShaderMixinSource but forget to initialize it before Compile.
Related errors
- Cannot clone mixin [ ] from a null parent
- An unknown EffectParameterType was found.
- ArgumentNullException
- ArgumentNullException: descriptions
- ArgumentNullException: paramName
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/2a1af2c36d1a75da.
Report an issue: GitHub.
Appendix: source
Thrown at sources/shaders/Stride.Shaders/ShaderMixinSource.cs:133
throw new ArgumentNullException("parent", $"Cannot clone mixin [{Name}] from a null parent");
Mixins.AddRange(parent.Mixins);
Macros.AddRange(parent.Macros);
foreach (var shaderBasic in parent.Compositions)
{
Compositions[shaderBasic.Key] = shaderBasic.Value;
}
}
/// <summary>
/// Clones from the specified <see cref="ShaderMixinSource"/>. Clones members too.
/// </summary>
/// <param name="parent">The parent mixin to clone from.</param>
/// <exception cref="System.ArgumentNullException">parent</exception>
public void DeepCloneFrom(ShaderMixinSource parent)
{
if (parent == null)
throw new ArgumentNullException("parent", $"Cannot deep clone mixin [{Name}] from a null parent");
foreach (var mixin in parent.Mixins)
Mixins.Add((ShaderClassCode)mixin.Clone());
Macros.AddRange(parent.Macros);
foreach (var shaderBasic in parent.Compositions)
{
Compositions[shaderBasic.Key] = (ShaderSource)shaderBasic.Value.Clone();
}
}
public override bool Equals(object against)
{
if (ReferenceEquals(null, against)) return false;
if (ReferenceEquals(this, against)) return true;
if (against.GetType() != this.GetType()) return false;
return Equals((ShaderMixinSource)against);
}
View on GitHub (pinned to 96fad776d2)