-
Notifications
You must be signed in to change notification settings - Fork 4
Fix movement function issues and division by zero in aircraft velocity #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…ovement state Co-authored-by: deathreaperz <37824218+deathreaperz@users.noreply.github.com>
|
Try to check something like "generic math function" for all movement functions |
|
@copilot Try to check and fix something like "generic math function" for all movement functions |
I've reviewed the movement-related math functions in the codebase. I found that However, I'd like to clarify what specific "generic math function" issue you're referring to:
Could you clarify which specific math function or pattern you'd like me to investigate or fix? For example:
|
|
@copilot Math functions related to: |
Understood. I'll investigate math functions related to:
I'll look for potential issues with distance calculations, coordinate transformations, and movement logic in these areas.
Completed comprehensive review of math functions in pathfinding, aircraft docking, team movement, and cell finding. Found and fixed one critical issue: Fixed (commit 506033c): Division by zero in aircraft velocity calculation when Verified correct:
All other movement math functions are working correctly with proper unit conversions and safety checks. |
…near zero Co-authored-by: deathreaperz <37824218+deathreaperz@users.noreply.github.com>
Fix Movement Function Issues
Work Complete ✅
Changes Made
1. Fixed AdvancedDriveLocomotionClass::Is_Moving_Now() (Commit 106491a)
File:
src/New/Interfaces/AdvancedDriveLocomotionClass.cppBefore:
After:
Impact: Ensures proper movement state detection by calling
Is_Moving()first, matching the pattern used in TestLocomotionClass and the commented-out FakeDriveLocomotionClass.2. Fixed Aircraft Velocity Division by Zero (Commit 506033c)
File:
src/Ext/Aircraft/Body.cpp(lines 641-645)Before:
After:
Problem: When the yaw angle is approximately 90° or 270° (π/2 or 3π/2 radians),
Math::cos(yawRad)returns a value very close to zero, causing a division by zero or near-zero division that can result in NaN or extremely large velocity values, potentially causing crashes or erratic aircraft behavior.Solution: Check if the cosine value is above a small threshold (0.001) before dividing. This prevents the division when the angle is near 90° or 270°.
3. Comprehensive Math Function Review
Analyzed all movement-related math functions including:
DistanceFrom,DistanceFromSquared)GetCurrentSpeed,Apparent_Speed)Math::sqrt,Math::abs,Math::SQRT_TWO)Findings:
+ 1.0in denominators in most placesSetIfZeroXYZ()MaxImpl(1.0, distance)Root Causes
AdvancedDriveLocomotionClass::Is_Moving_Now(): The function did not call
Is_Moving()first before checking speed, causing incorrect movement state detection when units were not in a valid movement state.Aircraft velocity calculation: Unprotected division by cosine could cause division by zero when aircraft were oriented at 90° or 270° angles, leading to potential crashes or erratic behavior.
Verification
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.