From aa36b6cefb01f72a33086a1f6ab12454269e6b4d Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 26 Feb 2025 21:36:09 -0600 Subject: [PATCH] previewing dialogs, don't crash the game --- src/dialogxml/dialogs/dialog.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/dialogxml/dialogs/dialog.cpp b/src/dialogxml/dialogs/dialog.cpp index b77a43f8..9f1a35df 100644 --- a/src/dialogxml/dialogs/dialog.cpp +++ b/src/dialogxml/dialogs/dialog.cpp @@ -50,6 +50,7 @@ std::mt19937 cDialog::ui_rand; extern std::map colour_map; extern bool check_for_interrupt(std::string); +extern void showError(std::string str1, cDialog* parent = nullptr); std::string cDialog::generateRandomString(){ // Not bothering to seed, because it doesn't actually matter if it's truly random. @@ -1170,16 +1171,23 @@ void cDialogIterator::increment() { } void preview_dialog_xml(fs::path dialog_xml) { - std::unique_ptr defn(load_dialog_defn(dialog_xml)); - cDialog dialog(*defn); - // Make every clickable control's click event close the dialog - for (auto control : dialog){ - try{ - control.second->attachClickHandler([](cDialog& me, std::string item_hit, eKeyMod mod) -> bool { - me.toast(false); - return true; - }); - }catch(...){} + try{ + std::unique_ptr defn(load_dialog_defn(dialog_xml)); + cDialog dialog(*defn); + + // Make every clickable control's click event close the dialog + for (auto control : dialog){ + try{ + control.second->attachClickHandler([](cDialog& me, std::string item_hit, eKeyMod mod) -> bool { + me.toast(false); + return true; + }); + }catch(...){} + } + dialog.run(); + }catch(std::exception& x) { + showError(x.what()); + }catch(std::string& x){ + showError(x); } - dialog.run(); } \ No newline at end of file