From 21c82a48146fb8afc5a56263a5da21300ba3137e Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Tue, 26 Jan 2021 16:30:59 +0100 Subject: [PATCH] FlightTasks: hotfix guard against accessing no task Safety guard for null pointer exception when accessing the current task when none is running. This could only happen if the running task was changed during the update because of command handling failing. Note: This is fixed on master in a different, better way. --- src/lib/flight_tasks/FlightTasks.hpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lib/flight_tasks/FlightTasks.hpp b/src/lib/flight_tasks/FlightTasks.hpp index 919e7be610..2c40b66fe1 100644 --- a/src/lib/flight_tasks/FlightTasks.hpp +++ b/src/lib/flight_tasks/FlightTasks.hpp @@ -150,14 +150,24 @@ public: /** * Sets an external yaw handler. The active flight task can use the yaw handler to implement a different yaw control strategy. */ - void setYawHandler(WeatherVane *ext_yaw_handler) {_current_task.task->setYawHandler(ext_yaw_handler);} + void setYawHandler(WeatherVane *ext_yaw_handler) + { + if (isAnyTaskActive()) { + _current_task.task->setYawHandler(ext_yaw_handler); + } + } /** * This method will re-activate current task. */ void reActivate(); - void updateVelocityControllerIO(const matrix::Vector3f &vel_sp, const matrix::Vector3f &thrust_sp) {_current_task.task->updateVelocityControllerIO(vel_sp, thrust_sp); } + void updateVelocityControllerIO(const matrix::Vector3f &vel_sp, const matrix::Vector3f &thrust_sp) + { + if (isAnyTaskActive()) { + _current_task.task->updateVelocityControllerIO(vel_sp, thrust_sp); + } + } private: