{"record":{"id":"f54ad90f84d53a74","repo":"stride3d/stride","slug":"boundingvolumebufferdownsamplelevel","errorCode":null,"errorMessage":"BoundingVolumeBufferDownsampleLevel","messagePattern":"BoundingVolumeBufferDownsampleLevel","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Rendering/Rendering/Images/LightShafts/LightShafts.cs","lineNumber":139,"sourceCode":"        {\n            base.Destroy();\n            minmaxVolumeEffectShader.Dispose();\n        }\n\n        public void Collect(RenderContext context)\n        {\n            lightShafts = context.VisibilityGroup.Tags.Get(CurrentLightShafts);\n        }\n\n        protected override void DrawCore(RenderDrawContext context)\n        {\n            if (lightShafts == null)\n                return; // Not collected\n\n            if (LightBufferDownsampleLevel < 1)\n                throw new ArgumentOutOfRangeException(nameof(LightBufferDownsampleLevel));\n            if (BoundingVolumeBufferDownsampleLevel < 1)\n                throw new ArgumentOutOfRangeException(nameof(BoundingVolumeBufferDownsampleLevel));\n\n            var depthInput = GetSafeInput(0);\n\n            // Create a min/max buffer generated from scene bounding volumes\n            var targetBoundingBoxBufferSize = new Size2(Math.Max(1, depthInput.Width / BoundingVolumeBufferDownsampleLevel), Math.Max(1, depthInput.Height / BoundingVolumeBufferDownsampleLevel));\n            var boundingBoxBuffer = NewScopedRenderTarget2D(targetBoundingBoxBufferSize.Width, targetBoundingBoxBufferSize.Height, PixelFormat.R32G32_Float);\n\n            // Buffer that holds the minimum distance in case of being inside the bounding box\n            var backSideRaycastBuffer = NewScopedRenderTarget2D(1, 1, PixelFormat.R32G32_Float);\n\n            // Create a single channel light buffer\n            PixelFormat lightBufferPixelFormat = needsColorLightBuffer ? PixelFormat.R16G16B16A16_Float : PixelFormat.R16_Float;\n            var targetLightBufferSize = new Size2(Math.Max(1, depthInput.Width / LightBufferDownsampleLevel), Math.Max(1, depthInput.Height / LightBufferDownsampleLevel));\n            var lightBuffer = NewScopedRenderTarget2D(targetLightBufferSize.Width, targetLightBufferSize.Height, lightBufferPixelFormat);\n            lightShaftsEffectShader.SetOutput(lightBuffer);\n            var lightShaftsParameters = lightShaftsEffectShader.Parameters;\n            lightShaftsParameters.Set(DepthBaseKeys.DepthStencil, depthInput); // Bind scene depth\n","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Rendering/Rendering/Images/LightShafts/LightShafts.cs#L121-L157","documentation":"LightShafts validates that the bounding-volume buffer downsample level is at least 1 before using it as a divisor for render target dimensions. A value of 0 (or negative) would produce a zero/negative buffer size or division by zero, so the renderer throws ArgumentOutOfRangeException in DrawCore.","triggerScenarios":"Setting LightShaftsComponent.BoundingVolumeBufferDownsampleLevel to 0 or a negative value (e.g. defaulting it from a serialized 0 int field) and then rendering a frame with light shafts enabled.","commonSituations":"A newly added component whose downsample property was never initialized, or a user setting the level to 0 believing it means 'no downsampling' when 1 actually means full resolution.","solutions":["Set BoundingVolumeBufferDownsampleLevel to 1 (full resolution) or higher","Clamp the value with Math.Max(1, value) when configuring the component","Check any serialized/UI code that can write 0 into this property"],"exampleFix":"// before\nlightShafts.BoundingVolumeBufferDownsampleLevel = 0;\n// after\nlightShafts.BoundingVolumeBufferDownsampleLevel = Math.Max(1, requestedLevel);","handlingStrategy":"validation","validationCode":"if (lightShafts.BoundingVolumeBufferDownsampleLevel < 1)\n    throw new ArgumentException(\"BoundingVolumeBufferDownsampleLevel must be >= 1\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never use 0 as a 'disabled' sentinel for downsample levels","Clamp serialized values on load with Math.Max(1, v)","Test rendering with freshly added LightShaft components"],"tags":["csharp","rendering","argument-out-of-range"],"backgroundTag":"argument-out-of-range","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}