{"record":{"id":"f3c8dc6d50375bba","repo":"stride3d/stride","slug":"blendmap-parameter-cannot-be-null-for-a-child-layer","errorCode":null,"errorMessage":"Blendmap parameter cannot be null for a child layer","messagePattern":"Blendmap parameter cannot be null for a child layer","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Rendering/Rendering/Materials/MaterialGeneratorContext.cs","lineNumber":215,"sourceCode":"            {\n                throw new InvalidOperationException(\"Cannot PopMaterial more than PushMaterial\");\n            }\n            return materialStack.Pop();\n        }\n\n        /// <summary>\n        /// Pushes a new layer with the specified blend map.\n        /// </summary>\n        /// <param name=\"blendMap\">The blend map used by this layer.</param>\n        public void PushLayer(IComputeScalar blendMap)\n        {\n            if (Step != MaterialGeneratorStep.GenerateShader)\n                return;\n\n            // We require a blend layer expect for the top level one.\n            if (currentLayerContext != null && blendMap == null)\n            {\n                throw new ArgumentNullException(nameof(blendMap), \"Blendmap parameter cannot be null for a child layer\");\n            }\n\n            var newLayer = new MaterialBlendLayerContext(this, currentLayerContext, blendMap);\n            if (currentLayerContext != null)\n            {\n                currentLayerContext.Children.Add(newLayer);\n            }\n            currentLayerContext = newLayer;\n        }\n\n        /// <summary>\n        /// Pops the current layer.\n        /// </summary>\n        public void PopLayer()\n        {\n            if (Step != MaterialGeneratorStep.GenerateShader)\n                return;\n","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Rendering/Rendering/Materials/MaterialGeneratorContext.cs#L197-L233","documentation":"MaterialGeneratorContext.PushLayer builds the blend-layer tree during shader generation. Every layer except the top-level one must know how it blends with its parent, so if a child layer is pushed with a null blendMap it throws ArgumentNullException for the blendMap parameter.","triggerScenarios":"Calling PushLayer(null) when another layer is already open (currentLayerContext != null) — i.e. pushing a child/nested layer without specifying its blend map, typically from a custom material descriptor with nested material layers.","commonSituations":"Custom IMaterialDescriptor with nested layers forgetting to supply a blending operation (e.g. MaterialBlendLayer with null BlendLayers map); copying sample code but omitting the blend map for inner layers.","solutions":["Pass a non-null blend map (e.g. an IMaterialBlendLayer with a valid blending operation) when pushing child layers","Restructure so only the top-level layer is pushed without a blend map","Set the blending in your MaterialBlendLayer (e.g. opacity/multiply/add) before PushLayer","If a child should inherit without blending, use a default blend map like opaque/multiply instead of null"],"exampleFix":"// before: child layer without blend map\ncontext.PushLayer(childLayer, null); // throws when nested\n// after: supply a blend map for child layers\ncontext.PushLayer(childLayer, new MaterialBlendLayer(context, blendMap) { BlendMap = blendMap });","handlingStrategy":"validation","validationCode":"if (context.CurrentLayer != null && blendMap == null)\n    blendMap = new MaterialBlendMap(); // or supply an explicit blend operation\ncontext.PushLayer(layer, blendMap);","typeGuard":"bool NeedsBlendMap(MaterialGeneratorContext ctx) => ctx.CurrentLayer != null;","tryCatchPattern":"try { context.PushLayer(layer, blendMap); }\ncatch (ArgumentNullException ex)\n{\n    logger.LogError(ex, \"Child layer pushed without blend map\");\n    context.PushLayer(layer, defaultBlendMap);\n}","preventionTips":["Always assign a blending operation to nested material layers","Only the top-level layer may omit the blend map","Review custom material descriptors for nested PushLayer calls during code review"],"tags":["material","generator","blend-layer","null-argument"],"backgroundTag":"null-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}