{"record":{"id":"7f04ce6ea03c2652","repo":"stride3d/stride","slug":"owner-s-fieldname-must-be-finite","errorCode":null,"errorMessage":"{owner}'s {fieldName} must be finite","messagePattern":"(.+?)'s (.+?) must be finite","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.BepuPhysics/Stride.BepuPhysics/Definitions/BepuAndStrideExtensions.cs","lineNumber":42,"sourceCode":"    public static SRigidPose ToStride(this BRigidPose pose) => Unsafe.As<BRigidPose, SRigidPose>(ref pose);\n    [MethodImpl(MethodImplOptions.AggressiveInlining)]\n    public static BBodyVelocity ToBepu(this SBodyVelocity pose) => Unsafe.As<SBodyVelocity, BBodyVelocity>(ref pose);\n    [MethodImpl(MethodImplOptions.AggressiveInlining)]\n    public static SBodyVelocity ToStride(this BBodyVelocity pose) => Unsafe.As<BBodyVelocity, SBodyVelocity>(ref pose);\n    [MethodImpl(MethodImplOptions.AggressiveInlining)]\n    public static NVector3 ToNumeric(this SVector3 vec) => Unsafe.As<SVector3, NVector3>(ref vec);\n    [MethodImpl(MethodImplOptions.AggressiveInlining)]\n    public static SVector3 ToStride(this NVector3 vec) => Unsafe.As<NVector3, SVector3>(ref vec);\n    [MethodImpl(MethodImplOptions.AggressiveInlining)]\n    public static NQuaternion ToNumeric(this SQuaternion qua) => Unsafe.As<SQuaternion, NQuaternion>(ref qua);\n    [MethodImpl(MethodImplOptions.AggressiveInlining)]\n    public static SQuaternion ToStride(this NQuaternion qua) => Unsafe.As<NQuaternion, SQuaternion>(ref qua);\n\n    [MethodImpl(MethodImplOptions.AggressiveInlining)]\n    public static void ValidateRange<T>(this SVector3 vec, T owner, [CallerMemberName] string? fieldName = null)\n    {\n        if (NVector3.AllWhereAllBitsSet(NVector3.IsFinite(vec)) == false)\n            throw new ArgumentOutOfRangeException($\"{owner}'s {fieldName} must be finite\");\n    }\n\n    [MethodImpl(MethodImplOptions.AggressiveInlining)]\n    public static void ValidateRange<T>(this SQuaternion quat, T owner, [CallerMemberName] string? fieldName = null)\n    {\n        if (quat.IsNormalized == false)\n            throw new ArgumentOutOfRangeException($\"{owner}'s {fieldName} must be normalized\");\n    }\n\n    [MethodImpl(MethodImplOptions.AggressiveInlining)]\n    public static void ValidateGreaterThanZeroFinite<T>(this float fp, T owner, [CallerMemberName] string? fieldName = null)\n    {\n        if (fp <= 0 || float.IsFinite(fp) == false)\n            throw new ArgumentOutOfRangeException($\"{owner}'s {fieldName} must be finite and greater than zero\");\n    }\n}\n","sourceCodeStart":24,"sourceCodeEnd":59,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.BepuPhysics/Stride.BepuPhysics/Definitions/BepuAndStrideExtensions.cs#L24-L59","documentation":"ValidateRange(this SVector3, ...) is a guard extension that ensures a vector value handed to the physics engine contains only finite components (no NaN or +/-Infinity). Bepu physics cannot simulate non-finite numbers and would corrupt the broadphase/solver, so it throws ArgumentOutOfRangeException with owner and field name context.","triggerScenarios":"Setting a collider/body vector property (e.g. size, scale, position offsets) to a value containing NaN or Infinity, often from a division by zero or a bad input file upstream.","commonSituations":"Computing mesh bounds from an empty mesh, dividing by zero scale, or loading model data where a dimension is 0 leading to NaN in derived quantities.","solutions":["Check float.IsFinite on each component before assigning, and fix the upstream computation producing NaN/Infinity.","Clamp or substitute defaults for invalid values (e.g. Vector3.One) before passing to the physics property.","Enable catching at the source: validate deserialized config/model data after load."],"exampleFix":"// before\nbox.Size = new Vector3(1f / zeroScale); // NaN\n// after\nvar s = zeroScale == 0 ? 1f : zeroScale;\nbox.Size = new Vector3(MathF.Max(1f / s, 1e-6f));","handlingStrategy":"validation","validationCode":"bool IsFinite(SVector3 v) => float.IsFinite(v.X) && float.IsFinite(v.Y) && float.IsFinite(v.Z);\nif (!IsFinite(value)) throw new ArgumentException(\"Vector must be finite before assignment\");","typeGuard":null,"tryCatchPattern":"try { vec.ValidateRange(this); property = vec; } catch (ArgumentOutOfRangeException ex) { log.Error($\"NaN/Infinity in {ex.ParamName}\", ex); }","preventionTips":["Guard divisions that produce vector components (scale, area)","Validate mesh/config data for NaN at load time","Sanitize computed values with float.IsFinite checks before physics assignment"],"tags":["physics","validation","nan","vector"],"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"}