From 98a35971afda8ee51981fc0c7610837b255ee17e Mon Sep 17 00:00:00 2001 From: Niklas Hauser Date: Wed, 13 Sep 2023 14:15:23 +0200 Subject: [PATCH] camera_capture: disable timer callback on stop Otherwise the capture_trampoline is called while g_camera_capture is a nullptr, which leads to a hardfault since the this pointer is invalid. --- src/drivers/camera_capture/camera_capture.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/drivers/camera_capture/camera_capture.cpp b/src/drivers/camera_capture/camera_capture.cpp index 91ab266311..7bf3813542 100644 --- a/src/drivers/camera_capture/camera_capture.cpp +++ b/src/drivers/camera_capture/camera_capture.cpp @@ -226,7 +226,9 @@ void CameraCapture::capture_trampoline(void *context, uint32_t chan_index, hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow) { - camera_capture::g_camera_capture->capture_callback(chan_index, edge_time, edge_state, overflow); + if (camera_capture::g_camera_capture) { + camera_capture::g_camera_capture->capture_callback(chan_index, edge_time, edge_state, overflow); + } } void @@ -359,6 +361,11 @@ CameraCapture::stop() work_cancel(HPWORK, &_work_publisher); + if (_capture_channel >= 0) { + up_input_capture_set(_capture_channel, Disabled, 0, nullptr, nullptr); + } + + if (camera_capture::g_camera_capture != nullptr) { delete (camera_capture::g_camera_capture); }