From 309e28c6d746faf271ccf0ec62251b146fcdcbb3 Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Fri, 19 Feb 2021 21:05:50 +0000 Subject: [PATCH] src/Viewer/viewmgr.cxx: removed asserts on inputs from aircraft/nasal code. The fgfs executable is the unit within which it makes sense to check preconditions with assert. We are not in control of aircraft code in the same way. This allows debug build of test-suite to check handling of out-of-range view numbers. --- src/Viewer/viewmgr.cxx | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Viewer/viewmgr.cxx b/src/Viewer/viewmgr.cxx index 767c9d849..75b6f6aae 100644 --- a/src/Viewer/viewmgr.cxx +++ b/src/Viewer/viewmgr.cxx @@ -80,9 +80,8 @@ FGViewMgr::init () SG_LOG(SG_VIEW, SG_ALERT, "Invalid /sim/current-view/view-number=" << _current << ". views.size()=" << views.size() - << ". Will assert false and use zero." + << ". Will use zero." ); - assert(0); _current = 0; } @@ -197,7 +196,13 @@ FGViewMgr::get_current_view() { if (views.empty()) return nullptr; - assert(_current >= 0 && _current < (int) views.size()); + if (_current < 0 || _current >= (int) views.size()) { + SG_LOG(SG_VIEW, SG_ALERT, "Invalid _current=" << _current + << ". views.size()=" << views.size() + << ". Will use zero." + ); + _current = 0; + } return views[_current]; } @@ -305,20 +310,14 @@ void FGViewMgr::setCurrentViewIndex(int newview) newview = i; } if (newview < 0) { - SG_LOG(SG_VIEW, SG_ALERT, - "Failed to find -ve newview=" << newview - << ". Will assert false and ignore." - ); - assert(0); + SG_LOG(SG_VIEW, SG_ALERT, "Failed to find -ve newview=" << newview); return; } } if (newview < 0 || newview >= (int) views.size()) { - SG_LOG(SG_VIEW, SG_ALERT, "Invalid newview=" << newview + SG_LOG(SG_VIEW, SG_ALERT, "Ignoring invalid newview=" << newview << ". views.size()=" << views.size() - << ". Will assert false and ignore." ); - assert(0); return; }