From 54dd828257bf19585478ce89faf11afc29500364 Mon Sep 17 00:00:00 2001 From: extollIT Enterprises Date: Mon, 10 Mar 2025 21:38:57 -0600 Subject: [PATCH 1/3] Do not crash with `Poco::SyntaxException` if encountering a property, expected to be integer, but was dynamic (i.e. contains something like `${someIntVar}`) --- src/gui/ProjectMGUI.h | 6 +++--- src/gui/SettingsWindow.cpp | 16 ++++++++++++++-- src/gui/SettingsWindow.h | 6 +++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/gui/ProjectMGUI.h b/src/gui/ProjectMGUI.h index 3083dc9..371e02b 100644 --- a/src/gui/ProjectMGUI.h +++ b/src/gui/ProjectMGUI.h @@ -124,14 +124,14 @@ class ProjectMGUI : public Poco::Util::Subsystem float _textScalingFactor{0.0f}; //!< The text scaling factor. + Poco::Logger& _logger{Poco::Logger::get("ProjectMGUI")}; //!< The class logger. + MainMenu _mainMenu{*this}; - SettingsWindow _settingsWindow{*this}; //!< The settings window. + SettingsWindow _settingsWindow{*this, _logger}; //!< The settings window. AboutWindow _aboutWindow{*this}; //!< The about window. HelpWindow _helpWindow; //!< Help window with shortcuts and tips. std::unique_ptr _toast; //!< Current toast to be displayed. bool _visible{false}; //!< Flag for settings window visibility. - - Poco::Logger& _logger{Poco::Logger::get("ProjectMGUI")}; //!< The class logger. }; diff --git a/src/gui/SettingsWindow.cpp b/src/gui/SettingsWindow.cpp index aec27a5..e2768f7 100644 --- a/src/gui/SettingsWindow.cpp +++ b/src/gui/SettingsWindow.cpp @@ -13,12 +13,14 @@ #include #include +#include -SettingsWindow::SettingsWindow(ProjectMGUI& gui) +SettingsWindow::SettingsWindow(ProjectMGUI& gui, Poco::Logger & logger) : _gui(gui) , _audioCapture(ProjectMSDLApplication::instance().getSubsystem()) , _userConfiguration(ProjectMSDLApplication::instance().UserConfiguration()) , _commandLineConfiguration(ProjectMSDLApplication::instance().CommandLineConfiguration()) + , _logger(logger) { } @@ -387,7 +389,17 @@ void SettingsWindow::IntegerSetting(const std::string& property, int defaultValu { ImGui::TableSetColumnIndex(1); - auto value = _userConfiguration->getInt(property, defaultValue); + int value = 0; + + try { + value = _userConfiguration->getInt(property, defaultValue); + _suppressPropertyWarnings.erase(property); + } catch (Poco::SyntaxException & ex) { + if (_suppressPropertyWarnings.find(property) == _suppressPropertyWarnings.end()) { + _suppressPropertyWarnings.insert(property); + _logger.warning("Encountered a non-integral property for '" + property + "', defaulting to zero and it will be clobbered if settings are saved."); + } + } if (ImGui::SliderInt(std::string("##integer_" + property).c_str(), &value, min, max)) { diff --git a/src/gui/SettingsWindow.h b/src/gui/SettingsWindow.h index be56d69..fb23e6f 100644 --- a/src/gui/SettingsWindow.h +++ b/src/gui/SettingsWindow.h @@ -4,6 +4,7 @@ #include #include +#include #include @@ -15,7 +16,7 @@ class SettingsWindow public: SettingsWindow() = delete; - explicit SettingsWindow(ProjectMGUI& gui); + explicit SettingsWindow(ProjectMGUI& gui, Poco::Logger & logger); /** * @brief Displays the settings window. @@ -134,6 +135,9 @@ class SettingsWindow Poco::AutoPtr _userConfiguration; Poco::AutoPtr _commandLineConfiguration; + std::set _suppressPropertyWarnings; + + Poco::Logger & _logger; FileChooser _pathChooser{FileChooser::Mode::Directory}; //!< The file chooser dialog to select preset and texture paths. }; From 800ac76e05eb7f5250d27086635b99acca7e50ea Mon Sep 17 00:00:00 2001 From: extollIT Enterprises Date: Mon, 10 Mar 2025 21:55:28 -0600 Subject: [PATCH 2/3] This property reference "device" seems incorrect, elsewhere in the repository the key "audio.device" is referenced. --- src/AudioCapture.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/AudioCapture.cpp b/src/AudioCapture.cpp index 44d2363..b6addb3 100644 --- a/src/AudioCapture.cpp +++ b/src/AudioCapture.cpp @@ -121,7 +121,7 @@ int AudioCapture::GetInitialAudioDeviceIndex(const AudioDeviceMap& deviceList) // Check if configured device is a number or string try { - audioDeviceIndex = _config->getInt("device", -1); + audioDeviceIndex = _config->getInt("audio.device", -1); if (deviceList.find(audioDeviceIndex) == deviceList.end()) { poco_debug(_logger, @@ -131,7 +131,7 @@ int AudioCapture::GetInitialAudioDeviceIndex(const AudioDeviceMap& deviceList) } catch (Poco::SyntaxException& ex) { - auto audioDeviceName = _config->getString("device", ""); + auto audioDeviceName = _config->getString("audio.device", ""); poco_debug_f1(_logger, R"(audio.device is set to non-numerical value. Searching for device name "%s".)", audioDeviceName); @@ -150,4 +150,4 @@ int AudioCapture::GetInitialAudioDeviceIndex(const AudioDeviceMap& deviceList) deviceList.at(audioDeviceIndex), audioDeviceIndex); return audioDeviceIndex; -} \ No newline at end of file +} From 1fa9a8654b2598582247cf1c0ac0ced9b68cd611 Mon Sep 17 00:00:00 2001 From: extollIT Enterprises Date: Mon, 10 Mar 2025 22:39:57 -0600 Subject: [PATCH 3/3] Enhancement, cover `SettingsWindow::IntegerSettingVec` integer retrieval with a safety wrapper as well. --- src/gui/SettingsWindow.cpp | 34 +++++++++++++++++++++------------- src/gui/SettingsWindow.h | 1 + 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/gui/SettingsWindow.cpp b/src/gui/SettingsWindow.cpp index e2768f7..c74a620 100644 --- a/src/gui/SettingsWindow.cpp +++ b/src/gui/SettingsWindow.cpp @@ -389,17 +389,7 @@ void SettingsWindow::IntegerSetting(const std::string& property, int defaultValu { ImGui::TableSetColumnIndex(1); - int value = 0; - - try { - value = _userConfiguration->getInt(property, defaultValue); - _suppressPropertyWarnings.erase(property); - } catch (Poco::SyntaxException & ex) { - if (_suppressPropertyWarnings.find(property) == _suppressPropertyWarnings.end()) { - _suppressPropertyWarnings.insert(property); - _logger.warning("Encountered a non-integral property for '" + property + "', defaulting to zero and it will be clobbered if settings are saved."); - } - } + auto value = _safeInt(property, defaultValue); if (ImGui::SliderInt(std::string("##integer_" + property).c_str(), &value, min, max)) { @@ -420,8 +410,9 @@ void SettingsWindow::IntegerSettingVec(const std::string& property1, const std:: ImGui::TableSetColumnIndex(1); int values[2] = { - _userConfiguration->getInt(property1, defaultValue1), - _userConfiguration->getInt(property2, defaultValue2)}; + _safeInt(property1, defaultValue1), + _safeInt(property2, defaultValue2) + }; if (ImGui::SliderInt2(std::string("##integer_" + property1 + property2).c_str(), values, min, max)) { @@ -573,3 +564,20 @@ void SettingsWindow::OverriddenSettingMarker() ImGui::EndTooltip(); } } + +int SettingsWindow::_safeInt(const std::string& property, int defaultValue) { + int value = defaultValue; + + try { + value = _userConfiguration->getInt(property, defaultValue); + } catch (Poco::SyntaxException & ex) { + if (_suppressPropertyWarnings.find(property) == _suppressPropertyWarnings.end()) { + _suppressPropertyWarnings.insert(property); + _logger.warning( + "Encountered a non-integral property for '" + property + "', defaulting to zero and it will be clobbered if settings are saved." + ); + } + } + return value; +} + diff --git a/src/gui/SettingsWindow.h b/src/gui/SettingsWindow.h index fb23e6f..4db61c3 100644 --- a/src/gui/SettingsWindow.h +++ b/src/gui/SettingsWindow.h @@ -132,6 +132,7 @@ class SettingsWindow bool _visible{false}; //!< Window visibility flag. bool _changed{false}; //!< true if the user changed any setting since the last save. + int _safeInt(const std::string& property, int defaultValue); Poco::AutoPtr _userConfiguration; Poco::AutoPtr _commandLineConfiguration;