stride3d/stride · error · ArgumentNullException

mixinTree

Error message

mixinTree

What it means

The ShaderMixinContext constructor throws ArgumentNullException("mixinTree") when the shader mixin source tree passed to it is null. The mixin tree is the root ShaderMixinSource that the context will compose shaders into, so a null value makes the context unusable. This is a fail-fast guard in the constructor.

Solutions

  1. Ensure the ShaderMixinSource passed to the constructor is created (new ShaderMixinSource(...)) before constructing ShaderMixinContext
  2. Trace back where the null tree originates (often a failed shader name lookup) and fix the source of the null
  3. Add a null check on the tree at the call site with a meaningful error message

Example fix

// before
var ctx = new ShaderMixinContext(GetTree(name), parameters, builders); // GetTree may return null
// after
var tree = GetTree(name) ?? new ShaderMixinSource(name);
var ctx = new ShaderMixinContext(tree, parameters, builders);
Defensive patterns

Strategy: validation

Validate before calling

if (mixinTree is null) throw new ArgumentNullException(nameof(mixinTree)); // validate before constructing
var ctx = new ShaderMixinContext(mixinTree, compilerParameters, registeredBuilders);

Type guard

static bool IsValidContextArgs(ShaderMixinSource t, ParameterCollection p, Dictionary<string, IShaderMixinBuilder> b) => t != null && p != null && b != null;

Try / catch

try { var ctx = new ShaderMixinContext(tree, parameters, builders); }
catch (ArgumentNullException ex) { logger.LogError(ex, "ShaderMixinContext argument was null: {Param}", ex.ParamName); throw; }

Prevention

When it happens

Trigger: Calling new ShaderMixinContext(null, compilerParameters, registeredBuilders) — e.g. when the shader source being compiled failed to produce a ShaderMixinSource earlier in the pipeline and the null result was passed straight through.

Common situations: Custom effect compiler pipelines that construct the context manually and pass a null mixin tree after a failed shader lookup or a null return from a factory method.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/5bf4d46b7d1a7c68. Report an issue: GitHub.

Appendix: source

Thrown at sources/shaders/Stride.Shaders.Effects/ShaderMixinContext.cs:39

        private readonly Stack<int> compositionIndices = new Stack<int>();
        private readonly StringBuilder compositionStringBuilder = new StringBuilder();

        private string compositionString = null;

        private readonly ShaderMixinSource currentMixinSourceTree;

        /// <summary>
        /// Initializes a new instance of the <see cref="ShaderMixinContext" /> class.
        /// </summary>
        /// <param name="mixinTree">The mixin tree.</param>
        /// <param name="compilerParameters">The default property container.</param>
        /// <param name="registeredBuilders">The registered builders.</param>
        /// <exception cref="System.ArgumentNullException">compilerParameters
        /// or
        /// registeredBuilders</exception>
        public ShaderMixinContext(ShaderMixinSource mixinTree, ParameterCollection compilerParameters, Dictionary<string, IShaderMixinBuilder> registeredBuilders)
        {
            if (mixinTree == null) throw new ArgumentNullException("mixinTree");
            if (compilerParameters == null)
                throw new ArgumentNullException("compilerParameters");

            if (registeredBuilders == null)
                throw new ArgumentNullException("registeredBuilders");

            // TODO: use a copy of the compilerParameters?
            this.currentMixinSourceTree = mixinTree;
            this.compilerParameters = compilerParameters;
            this.registeredBuilders = registeredBuilders;
            this.parameterCollections = new Stack<ParameterCollection>();
        }

        /// <summary>
        /// Gets or sets the child effect.
        /// </summary>
        /// <value>The child effect.</value>
        public string ChildEffectName { get; set; }

View on GitHub (pinned to 96fad776d2)