diff --git a/plugins/dwarfmonitor.cpp b/plugins/dwarfmonitor.cpp index 29d0198b3..7fadff32f 100644 --- a/plugins/dwarfmonitor.cpp +++ b/plugins/dwarfmonitor.cpp @@ -163,7 +163,6 @@ namespace dm_lua { delete out; out = NULL; } - lua_close(state); } bool init_call (const char *func) { @@ -1873,6 +1872,12 @@ static bool set_monitoring_mode(const string &mode, const bool &state) if (!is_enabled) return false; + /* + NOTE: although we are not touching DF directly but there might be + code running that uses these values. So this could use another mutex + or just suspend the core while we edit our values. + */ + CoreSuspender guard; if (mode == "work" || mode == "all") { @@ -1908,7 +1913,10 @@ static bool load_config() DFhackCExport command_result plugin_enable(color_ostream &out, bool enable) { if (enable) + { + CoreSuspender guard; load_config(); + } if (is_enabled != enable) { if (!INTERPOSE_HOOK(dwarf_monitor_hook, render).apply(enable)) @@ -1963,16 +1971,19 @@ static command_result dwarfmonitor_cmd(color_ostream &out, vector & par } else if (cmd == 's' || cmd == 'S') { + CoreSuspender guard; if(Maps::IsValid()) Screen::show(dts::make_unique(), plugin_self); } else if (cmd == 'p' || cmd == 'P') { + CoreSuspender guard; if(Maps::IsValid()) Screen::show(dts::make_unique(), plugin_self); } else if (cmd == 'r' || cmd == 'R') { + CoreSuspender guard; load_config(); } else @@ -2024,7 +2035,7 @@ DFhackCExport command_result plugin_init(color_ostream &out, std::vector