diff options
author | Rafael Lima <rafael.palma.lima@gmail.com> | 2024-09-06 21:33:27 +0200 |
---|---|---|
committer | Rafael Lima <rafael.palma.lima@gmail.com> | 2024-09-18 20:59:55 +0200 |
commit | 57ecae2843c80d67ab9a3aaaf004fe131c4f13ae (patch) | |
tree | e6baf2f8c7334a0fb490567bed404041e9b00cd0 /sc | |
parent | c54b8e5682373934c826702a965f97f4a7a36193 (diff) |
tdf#162760 Fix solver crashing with unset parameters
This patch fixes 2 related issues:
1) Solver engines may crash internally and we need to catch these exceptions and inform the user instead of letting Calc crash entirely.
2) When initializing solver settings, we only set the default values for the first engine; we need to set the defaults for all engines.
Change-Id: Ia598f7c17c25b5d6277f2ce24d2f4d552f897fe0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172955
Reviewed-by: Rafael Lima <rafael.palma.lima@gmail.com>
Tested-by: Jenkins
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/SolverSettings.hxx | 1 | ||||
-rw-r--r-- | sc/inc/globstr.hrc | 1 | ||||
-rw-r--r-- | sc/source/core/data/SolverSettings.cxx | 14 | ||||
-rw-r--r-- | sc/source/ui/miscdlgs/optsolver.cxx | 16 |
4 files changed, 26 insertions, 6 deletions
diff --git a/sc/inc/SolverSettings.hxx b/sc/inc/SolverSettings.hxx index 7f328ed89eed..dd5afc5211fa 100644 --- a/sc/inc/SolverSettings.hxx +++ b/sc/inc/SolverSettings.hxx @@ -165,6 +165,7 @@ private: OUString m_sSocialConstant; OUString m_sConstrictionCoeff; OUString m_sMutationProbability; + // SCO only OUString m_sLibrarySize; css::uno::Sequence<css::beans::PropertyValue> m_aEngineOptions; diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc index e0838445e736..49a186325f46 100644 --- a/sc/inc/globstr.hrc +++ b/sc/inc/globstr.hrc @@ -520,6 +520,7 @@ #define STR_INVALIDVAR NC_("STR_INVALIDVAR", "Undefined name for variable cell.") #define STR_INVALIDFORM NC_("STR_INVALIDFORM", "Undefined name as formula cell.") #define STR_NOFORMULA NC_("STR_NOFORMULA", "Formula cell must contain a formula.") +#define STR_SOLVER_ENGINE_ERROR NC_("STR_SOLVER_ENGINE_ERROR", "An internal error occurred while running the solver engine.") #define STR_INVALIDINPUT NC_("STR_INVALIDINPUT", "Invalid input.") #define STR_INVALIDCONDITION NC_("STR_INVALIDCONDITION", "Invalid condition.") #define STR_QUERYREMOVE NC_("STR_QUERYREMOVE", "Should the entry\n#\nbe deleted?") diff --git a/sc/source/core/data/SolverSettings.cxx b/sc/source/core/data/SolverSettings.cxx index 333751d26734..9917cdcc59e7 100644 --- a/sc/source/core/data/SolverSettings.cxx +++ b/sc/source/core/data/SolverSettings.cxx @@ -763,18 +763,24 @@ void SolverSettings::ResetToDefaults() m_sVariableCells = ""; m_sMSEngineId = "1"; - // The default solver engine is the first implementation available css::uno::Sequence<OUString> aEngineNames; css::uno::Sequence<OUString> aDescriptions; ScSolverUtil::GetImplementations(aEngineNames, aDescriptions); + + // tdf#162760 Set the parameters of all available solver engines to the default values + for (const auto& sEngine : aEngineNames) + { + css::uno::Sequence<css::beans::PropertyValue> aEngineProps + = ScSolverUtil::GetDefaults(sEngine); + SetEngineOptions(aEngineProps); + } + + // The default solver engine is the first implementation available m_sLOEngineName = aEngineNames[0]; // Default engine options m_aEngineOptions = ScSolverUtil::GetDefaults(m_sLOEngineName); - // Default solver engine options - SetEngineOptions(m_aEngineOptions); - // Clear all constraints m_aConstraints.clear(); } diff --git a/sc/source/ui/miscdlgs/optsolver.cxx b/sc/source/ui/miscdlgs/optsolver.cxx index 358754a884fe..a406e361c998 100644 --- a/sc/source/ui/miscdlgs/optsolver.cxx +++ b/sc/source/ui/miscdlgs/optsolver.cxx @@ -1116,8 +1116,20 @@ bool ScOptSolverDlg::CallSolver() // return true -> close dialog after cal } } - xSolver->solve(); - bool bSuccess = xSolver->getSuccess(); + // tdf#162760 The solver engine may crash unexpectedly, so we need a try...catch here + bool bSuccess(false); + try + { + xSolver->solve(); + bSuccess = xSolver->getSuccess(); + } + catch (const uno::RuntimeException&) + { + std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(), + VclMessageType::Error, VclButtonsType::Ok, + ScResId(STR_SOLVER_ENGINE_ERROR))); + xBox->run(); + } xProgress->response(RET_CLOSE); |