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 +} 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..c74a620 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,7 @@ void SettingsWindow::IntegerSetting(const std::string& property, int defaultValu { ImGui::TableSetColumnIndex(1); - auto value = _userConfiguration->getInt(property, defaultValue); + auto value = _safeInt(property, defaultValue); if (ImGui::SliderInt(std::string("##integer_" + property).c_str(), &value, min, max)) { @@ -408,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)) { @@ -561,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 be56d69..4db61c3 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. @@ -131,9 +132,13 @@ 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; + std::set _suppressPropertyWarnings; + + Poco::Logger & _logger; FileChooser _pathChooser{FileChooser::Mode::Directory}; //!< The file chooser dialog to select preset and texture paths. };