stride3d/stride · error · ArgumentOutOfRangeException

value

Error message

value

What it means

GestureConfigLongPress.MaximumDistance (maximumTransDst) throws ArgumentOutOfRangeException with paramName "value" when the assigned maximum translation distance is negative. The touch must stay within this radius of its start point; radius is a magnitude >= 0.

Solutions

  1. Assign a non-negative distance, e.g. MaximumDistance = 30f
  2. Apply Math.Abs() to computed values before assignment
  3. Sanitize config-loaded values, treating negatives as invalid

Example fix

// before
longPressConfig.MaximumDistance = -1f;
// after
longPressConfig.MaximumDistance = 30f;
Defensive patterns

Strategy: validation

Validate before calling

if (float.IsNaN(d) || d < 0f) throw new ArgumentException("MaximumDistance must be >= 0");
longPressConfig.MaximumDistance = d;

Type guard

bool IsValidRadius(float v) => !float.IsNaN(v) && v >= 0f;

Try / catch

try { longPressConfig.MaximumDistance = d; }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "value")
{
    longPressConfig.MaximumDistance = 30f;
}

Prevention

When it happens

Trigger: Assigning a negative float to MaximumDistance on an unfrozen GestureConfigLongPress, typically from signed math or bad config defaults.

Common situations: Computing a radius from a delta without Abs(); -1 'unset' sentinel values in config files; copy-paste sign errors.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/e42820104c665e47. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Input/Gestures/GestureConfigLongPress.cs:29

    public sealed class GestureConfigLongPress : GestureConfig
    {
        /// <summary>
        /// The value represents the maximum distance a finger can translate during the longPress action.
        /// </summary>
        /// <exception cref="ArgumentOutOfRangeException">The value has to be positive.</exception>
        /// <exception cref="InvalidOperationException">Tried to modify the configuration after it has been frozen by the system.</exception>
        /// <remarks>
        /// By increasing this value, the user allows small movements of the fingers during the long press.
        /// By decreasing this value, the user forbids any movements during the long press.</remarks>
        public float MaximumTranslationDistance
        {
            get { return maximumTransDst; }
            set
            {
                CheckNotFrozen();

                if (value < 0)
                    throw new ArgumentOutOfRangeException("value");

                maximumTransDst = value;
            }
        }
        private float maximumTransDst;

        /// <summary>
        /// The time the user has to hold his finger on the screen to trigger the gesture.
        /// </summary>
        /// <exception cref="InvalidOperationException">Tried to modify the configuration after it has been frozen by the system.</exception>
        public TimeSpan RequiredPressTime
        {
            get { return requiredPressTime; }
            set
            {
                CheckNotFrozen();

                requiredPressTime = value;

View on GitHub (pinned to 96fad776d2)