From a4c781911762cadfe95c7494ac5bd0b0140fad8a Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Sun, 19 May 2024 17:39:50 +1000 Subject: [PATCH] AC_Fence: clear breach of disabled fence skip breach checks if no fences correct initialisation of _num_fences in the case of no fences in eeprom --- libraries/AC_Fence/AC_Fence.cpp | 1 + libraries/AC_Fence/AC_PolyFence_loader.cpp | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libraries/AC_Fence/AC_Fence.cpp b/libraries/AC_Fence/AC_Fence.cpp index b88befe040..36fb7fbb32 100644 --- a/libraries/AC_Fence/AC_Fence.cpp +++ b/libraries/AC_Fence/AC_Fence.cpp @@ -635,6 +635,7 @@ bool AC_Fence::check_fence_polygon() { if (!(get_enabled_fences() & AC_FENCE_TYPE_POLYGON)) { // not enabled; no breach + clear_breach(AC_FENCE_TYPE_POLYGON); return false; } diff --git a/libraries/AC_Fence/AC_PolyFence_loader.cpp b/libraries/AC_Fence/AC_PolyFence_loader.cpp index 509e039a84..b97334476e 100644 --- a/libraries/AC_Fence/AC_PolyFence_loader.cpp +++ b/libraries/AC_Fence/AC_PolyFence_loader.cpp @@ -227,7 +227,7 @@ bool AC_PolyFence_loader::breached() const // returns true if location is outside the boundary bool AC_PolyFence_loader::breached(const Location& loc) const { - if (!loaded()) { + if (!loaded() || total_fence_count() == 0) { return false; } @@ -493,13 +493,15 @@ bool AC_PolyFence_loader::index_eeprom() if (!count_eeprom_fences()) { return false; } + + void_index(); + if (_eeprom_fence_count == 0) { + _num_fences = 0; _load_attempted = false; return true; } - void_index(); - Debug("Fence: Allocating %u bytes for index", (unsigned)(_eeprom_fence_count*sizeof(FenceIndex))); _index = NEW_NOTHROW FenceIndex[_eeprom_fence_count];