{"record":{"id":"d33b1609805d061c","repo":"stride3d/stride","slug":"step-cannot-be-zero-or-negative","errorCode":null,"errorMessage":"Step cannot be zero or negative.","messagePattern":"Step cannot be zero or negative\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/CurveEditor/Axes/AxisBase.cs","lineNumber":381,"sourceCode":"        /// <summary>\n        /// Occurs when the transform changed (size or axis range was changed).\n        /// </summary>\n        public event EventHandler TransformChanged;\n\n        /// <summary>\n        /// Creates tick values at the specified interval.\n        /// </summary>\n        /// <param name=\"from\">The start value.</param>\n        /// <param name=\"to\">The end value.</param>\n        /// <param name=\"step\">The interval.</param>\n        /// <param name=\"maxTicks\">The maximum number of ticks (optional). The default value is 1000.</param>\n        /// <returns>A sequence of values.</returns>\n        /// <exception cref=\"System.ArgumentException\">Step cannot be zero or negative.;step</exception>\n        public static IList<double> CreateTickValues(double from, double to, double step, int maxTicks = 1000)\n        {\n            if (step <= 0)\n            {\n                throw new ArgumentException(\"Step cannot be zero or negative.\", nameof(step));\n            }\n\n            if (to <= from && step > 0)\n            {\n                step *= -1;\n            }\n\n            var startValue = Math.Round(from / step) * step;\n            var numberOfValues = Math.Max((int)((to - from) / step), 1);\n            var epsilon = step * 1e-3 * Math.Sign(step);\n            var values = new List<double>(numberOfValues);\n\n            for (var k = 0; k < maxTicks; k++)\n            {\n                var lastValue = startValue + (step * k);\n\n                // If we hit the maximum value before reaching the max number of ticks, exit\n                if (lastValue > to + epsilon)","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/CurveEditor/Axes/AxisBase.cs#L363-L399","documentation":"AxisBase.CreateTickValues generates tick positions for an axis between 'from' and 'to'. A non-positive step would cause an infinite loop or divide-by-zero in tick computation, so the method eagerly rejects it with ArgumentException. Step must be strictly greater than zero; direction is handled internally by negating the step when to <= from.","triggerScenarios":"Calling CreateTickValues(from, to, 0), a negative step, or GetTickValues on an axis whose Step property was set to 0 or a negative value (e.g. from data binding or a deserialized default).","commonSituations":"Setting Step before other axis initialization leaves it at 0; user-editable step fields bound to the axis allow 0 or negative input; unit tests constructing an AxisBase without setting Step.","solutions":["Ensure the axis Step property is set to a positive value before generating ticks","Clamp/guard the step: if (step <= 0) step = defaultStep before calling","If step comes from UI input, validate > 0 in the view model before binding","Wrap in try/catch when step originates from untrusted input"],"exampleFix":"// before\naxis.Step = userStep; // may be 0\nvar ticks = axis.GetTickValues();\n// after\naxis.Step = userStep > 0 ? userStep : DefaultStep;\nvar ticks = axis.GetTickValues();","handlingStrategy":"validation","validationCode":"if (step <= 0) throw new ArgumentException(\"step must be > 0\", nameof(step));\nvar ticks = AxisBase.CreateTickValues(from, to, step);","typeGuard":"bool IsValidStep(double step) => step > 0;","tryCatchPattern":"try { ticks = AxisBase.CreateTickValues(from, to, step); }\ncatch (ArgumentException) { ticks = Array.Empty<double>(); }","preventionTips":["Initialize axis Step to a positive default in constructors","Validate user-bound step values in the view model before assignment","Add unit tests covering step = 0 and negative step"],"tags":["argument-exception","curve-editor","validation"],"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"}