stride3d/stride · error · ArgumentException
Step cannot be zero or negative.
Error message
Step cannot be zero or negative.
What it means
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.
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
Example fix
// before axis.Step = userStep; // may be 0 var ticks = axis.GetTickValues(); // after axis.Step = userStep > 0 ? userStep : DefaultStep; var ticks = axis.GetTickValues();
Defensive patterns
Strategy: validation
Validate before calling
if (step <= 0) throw new ArgumentException("step must be > 0", nameof(step));
var ticks = AxisBase.CreateTickValues(from, to, step); Type guard
bool IsValidStep(double step) => step > 0;
Try / catch
try { ticks = AxisBase.CreateTickValues(from, to, step); }
catch (ArgumentException) { ticks = Array.Empty<double>(); } Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Cannot add an asset with an empty Id
- Vector component 'W' is invalid, only 'X' and 'Y' are…
- Vector component 'W' is invalid, only 'X' and 'Y' are…
- Vector component 'W' is invalid, only 'X', 'Y' and 'Z' are…
- Vector component 'W' is invalid, only 'X', 'Y' and 'Z' are…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/d33b1609805d061c.
Report an issue: GitHub.
Appendix: source
Thrown at sources/editor/Stride.Assets.Presentation/CurveEditor/Axes/AxisBase.cs:381
/// <summary>
/// Occurs when the transform changed (size or axis range was changed).
/// </summary>
public event EventHandler TransformChanged;
/// <summary>
/// Creates tick values at the specified interval.
/// </summary>
/// <param name="from">The start value.</param>
/// <param name="to">The end value.</param>
/// <param name="step">The interval.</param>
/// <param name="maxTicks">The maximum number of ticks (optional). The default value is 1000.</param>
/// <returns>A sequence of values.</returns>
/// <exception cref="System.ArgumentException">Step cannot be zero or negative.;step</exception>
public static IList<double> CreateTickValues(double from, double to, double step, int maxTicks = 1000)
{
if (step <= 0)
{
throw new ArgumentException("Step cannot be zero or negative.", nameof(step));
}
if (to <= from && step > 0)
{
step *= -1;
}
var startValue = Math.Round(from / step) * step;
var numberOfValues = Math.Max((int)((to - from) / step), 1);
var epsilon = step * 1e-3 * Math.Sign(step);
var values = new List<double>(numberOfValues);
for (var k = 0; k < maxTicks; k++)
{
var lastValue = startValue + (step * k);
// If we hit the maximum value before reaching the max number of ticks, exit
if (lastValue > to + epsilon)View on GitHub (pinned to 96fad776d2)