Skip to content

Commit fcdb49b

Browse files
committed
Work around an issue in CHoverAirMoveType::UpdateBanking() when circlingPos == owner->pos caused NaNs
1 parent a9e11ed commit fcdb49b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

rts/Sim/MoveTypes/HoverAirMoveType.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,11 @@ void CHoverAirMoveType::UpdateBanking(bool noBanking)
687687
rightDir2D = frontDir.cross(UpVector);
688688

689689

690-
if (!owner->upright)
691-
wantedPitch = (circlingPos.y - owner->pos.y) / circlingPos.distance(owner->pos);
690+
if (!owner->upright) {
691+
// std::max() is here to guard around the case when circlingPos == owner->pos,
692+
// which caused NaNs all over the place
693+
wantedPitch = (circlingPos.y - owner->pos.y) / std::max(0.01f, circlingPos.distance(owner->pos));
694+
}
692695

693696
wantedPitch *= (aircraftState == AIRCRAFT_FLYING && flyState == FLY_ATTACKING && circlingPos.y != owner->pos.y);
694697
currentPitch = mix(currentPitch, wantedPitch, 0.05f);

0 commit comments

Comments
 (0)