Fix crash if you cancel the scenario selection

This commit is contained in:
2024-08-21 22:09:58 -04:00
parent 2fc097736c
commit 20c53fb2ed
2 changed files with 13 additions and 3 deletions

View File

@@ -114,11 +114,22 @@ public:
void run(std::function<void(cDialog&)> onopen = nullptr); // cd_run_dialog void run(std::function<void(cDialog&)> onopen = nullptr); // cd_run_dialog
/// Get the result of the dialog. /// Get the result of the dialog.
/// @tparam type The result type. /// @tparam type The result type.
/// @throw boost::bad_any_cast if the provided result type is different from the type set by getResult(). /// @throw boost::bad_any_cast if the provided result type is different from the type set by setResult().
/// @return The dialog's result. /// @return The dialog's result.
template<typename type> type getResult() const { template<typename type> type getResult() const {
return boost::any_cast<type>(result); return boost::any_cast<type>(result);
} }
/// Check if the dialog has a result.
/// @return true if setResult() was called, otherwise false.
bool hasResult() const {
return !result.empty();
}
/// Query the type of the result.
/// @tparam type The result type to query.
/// @return true if the type matches that set by setResult().
template<typename type> bool resultIs() const {
return result.type() == typeid(type);
}
/// Set the result of the dialog. /// Set the result of the dialog.
/// @tparam type The result type. /// @tparam type The result type.
/// @param val The result value. /// @param val The result value.

View File

@@ -1508,8 +1508,6 @@ class cChooseScenario {
} }
bool doCancel() { bool doCancel() {
scen_header_type null;
me.setResult<scen_header_type>(null);
me.toast(false); me.toast(false);
return true; return true;
} }
@@ -1576,6 +1574,7 @@ public:
} }
me.run(); me.run();
if(!me.hasResult()) return scen_header_type{};
scen_header_type scen = me.getResult<scen_header_type>(); scen_header_type scen = me.getResult<scen_header_type>();
if(scen.file.empty()){ if(scen.file.empty()){
std::ostringstream error; std::ostringstream error;