From 927ee745f20ee942ac1123bbb08111f3136525b6 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Fri, 22 Mar 2024 18:22:47 -0400 Subject: [PATCH] [TD]protect against bad pref value - this is a temporary measure to prevent problems caused by a bad value for LineStandard parameter. A previous devel version stored on invalid value. This patch can be removed before moving to production. - this condition can be corrected by editing LineStandard to 0, 1 or 2. a plethora of warning messages is issued until the parameter is corrected. --- src/Mod/TechDraw/App/LineGenerator.cpp | 11 +++++++++++ src/Mod/TechDraw/App/Preferences.cpp | 14 +++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Mod/TechDraw/App/LineGenerator.cpp b/src/Mod/TechDraw/App/LineGenerator.cpp index 21952ffd55..8770c137f1 100644 --- a/src/Mod/TechDraw/App/LineGenerator.cpp +++ b/src/Mod/TechDraw/App/LineGenerator.cpp @@ -362,6 +362,17 @@ std::string LineGenerator::getLineStandardsBody() { int activeStandard = Preferences::lineStandard(); std::vector choices = getAvailableLineStandards(); + if (activeStandard < 0 || + (size_t) activeStandard >= choices.size()) { + // there is a condition where the LineStandard parameter exists, but is -1 (the + // qt value for no current index in a combobox). This is likely caused by an old + // development version writing an unvalidated value. In this case, the existing but + // invalid value will be returned. This is a temporary fix and can be removed for + // production. + // Preferences::lineStandard() will print a message about this every time it is called + // (lots of messages!). + activeStandard = 0; + } return getBodyFromString(choices.at(activeStandard)); } diff --git a/src/Mod/TechDraw/App/Preferences.cpp b/src/Mod/TechDraw/App/Preferences.cpp index ae35b68fa0..3517849a19 100644 --- a/src/Mod/TechDraw/App/Preferences.cpp +++ b/src/Mod/TechDraw/App/Preferences.cpp @@ -23,7 +23,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ # include - +# include # include #endif @@ -422,6 +422,18 @@ bool Preferences::SectionUsePreviousCut() //! an index into the list of available line standards/version found in LineGroupDirectory int Preferences::lineStandard() { + // there is a condition where the LineStandard parameter exists, but is -1 (the + // qt value for no current index in a combobox). This is likely caused by an old + // development version writing an unvalidated value. In this case, the + // existing but invalid value will be returned. This is a temporary fix and + // can be removed for production. + // this message will appear many times if the parameter is invalid. + int parameterValue = getPreferenceGroup("Standards")->GetInt("LineStandard", 1); + if (parameterValue < 0) { + Base::Console().Warning(qPrintable(QApplication::translate( + "Preferences", "The LineStandard parameter is invalid. Using zero instead.", nullptr))); + return 0; + } return getPreferenceGroup("Standards")->GetInt("LineStandard", 1); }