{"record":{"id":"c1958af4677c1778","repo":"stride3d/stride","slug":"must-be-0","errorCode":null,"errorMessage":"Must be >= 0","messagePattern":"Must be >= 0","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/Size3.cs","lineNumber":231,"sourceCode":"    /// Implements the !=.\n    /// </summary>\n    /// <param name=\"left\">The left.</param>\n    /// <param name=\"right\">The right.</param>\n    /// <returns>The result of the operator.</returns>\n    public static bool operator !=(Size3 left, Size3 right)\n    {\n        return !left.Equals(right);\n    }\n\n    /// <summary>\n    /// Calculates the next up mip-level (*2) of this size.\n    /// </summary>\n    /// <returns>A next up mip-level Size3.</returns>\n    public readonly Size3 Up2(int count = 1)\n    {\n        if (count < 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(count), \"Must be >= 0\");\n        }\n\n        return new Size3(Math.Max(1, Width << count), Math.Max(1, Height << count), Math.Max(1, Depth << count));\n    }\n\n    /// <summary>\n    /// Calculates the next down mip-level (/2) of this size.\n    /// </summary>\n    /// <param name=\"count\">The count.</param>\n    /// <returns>A next down mip-level Size3.</returns>\n    public readonly Size3 Down2(int count = 1)\n    {\n        if (count < 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(count), \"Must be >= 0\");\n        }\n\n        return new Size3(Math.Max(1, Width >> count), Math.Max(1, Height >> count), Math.Max(1, Depth >> count));","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/Size3.cs#L213-L249","documentation":"Size3.Up2(count) computes a mip level size 'count' levels up by left-shifting Width, Height and Depth. A negative count would shift in the wrong direction and corrupt the mip math, so the library throws ArgumentOutOfRangeException requiring count >= 0.","triggerScenarios":"Calling size.Up2(-1) or any negative count, often from a mip-level variable that was decremented below zero or computed as (currentLevel - targetLevel) with swapped operands.","commonSituations":"Mip-chain generation loops where the level index underflows; passing relative level deltas that turn out negative; refactored code calling Up2 where Down2 was intended with a negative count.","solutions":["Pass a non-negative count to Up2","If the size must shrink, call Down2 with a positive count instead of Up2 with a negative one","Validate or Math.Max(0, levelDelta) the computed mip delta before calling"],"exampleFix":"// before\nvar bigger = size.Up2(targetLevel - currentLevel); // negative if target < current\n// after\nvar delta = targetLevel - currentLevel;\nvar bigger = delta >= 0 ? size.Up2(delta) : size.Down2(-delta);","handlingStrategy":"validation","validationCode":"if (count >= 0) { var up = size.Up2(count); }","typeGuard":"bool IsValidMipDelta(int c) => c >= 0;","tryCatchPattern":"try { var up = size.Up2(count); }\ncatch (ArgumentOutOfRangeException ex) { /* ex.ParamName == \"count\"; clamp to 0 and retry */ }","preventionTips":["Compute level deltas with correct operand order","Branch between Up2 and Down2 based on delta sign","Clamp with Math.Max(0, delta) before calls"],"tags":["mathematics","argument-out-of-range","mipmap","size3"],"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-15T23:17:13.987Z"}