From db844c3bd61dbe5c7485e9f557b4a68ec5fa5027 Mon Sep 17 00:00:00 2001 From: bkleiner Date: Mon, 2 Sep 2024 18:04:23 +0200 Subject: [PATCH] stick_vector: ensure we do not divide by zero --- src/flight/input.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/flight/input.c b/src/flight/input.c index 7d66ce16e..4c7cd56e0 100644 --- a/src/flight/input.c +++ b/src/flight/input.c @@ -23,9 +23,9 @@ vec3_t input_stick_vector(float rx_input[]) { .yaw = fastcos(roll) * fastcos(pitch), }; - const float length = (stickvector.roll * stickvector.roll + stickvector.pitch * stickvector.pitch); - if (length > 0) { - const float mag = 1.0f / sqrtf(length / (1 - stickvector.yaw * stickvector.yaw)); + if (stickvector.yaw < 1.0f) { + const float length = (stickvector.roll * stickvector.roll + stickvector.pitch * stickvector.pitch); + const float mag = 1.0f / sqrtf(length / (1.0f - stickvector.yaw * stickvector.yaw)); stickvector.roll *= mag; stickvector.pitch *= mag; } else {