From a91f74c86c11ca4933f3eb02b970120812adb965 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Thu, 22 Feb 2024 17:21:57 +0100 Subject: [PATCH] fixed a crash bug when editing custom_settings --- config.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/config.cpp b/config.cpp index c3b2b1b8..193381e9 100644 --- a/config.cpp +++ b/config.cpp @@ -340,6 +340,8 @@ struct custom_setting : public setting { function custom_viewer; function custom_value; function custom_affect; + function custom_load; + void show_edit_option(int key) override { custom_viewer(key); } supersaver *make_saver() override { throw hr_exception("make_saver for custom_setting"); } bool affects(void *v) override { return custom_affect(v); } @@ -349,6 +351,14 @@ struct custom_setting : public setting { add_to_changed(this); } } + virtual void load_from(const string& s) { + if(saver) { saver->load(s); return; } + if(!custom_load) { + println(hlog, "cannot load parameter: ", parameter_name, " from: ", s); + throw hr_exception("parameter cannot be loaded"); + } + custom_load(s); + } }; struct local_parameter_set { @@ -832,6 +842,7 @@ custom_setting* param_custom(T& val, const string& s, function menui u->custom_viewer = menuitem; u->custom_value = [&val] () { return (int) val; }; u->custom_affect = [&val] (void *v) { return &val == v; }; + u->custom_load = [&val] (const string& s) { val = (T) parseint(s); }; u->default_key = key; u->is_editable = true; auto f = &*u;