From 6bcb6e559e006e08be29e078513098ae0dbdc23e Mon Sep 17 00:00:00 2001 From: Barinade Date: Wed, 25 Sep 2024 00:48:06 -0500 Subject: [PATCH] stop holding the calcparam xml file handle forever --- src/Etterna/MinaCalc/MinaCalc.cpp | 1 + src/Etterna/MinaCalc/UlbuBase.h | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Etterna/MinaCalc/MinaCalc.cpp b/src/Etterna/MinaCalc/MinaCalc.cpp index 6b14790688..3b385e5fe8 100644 --- a/src/Etterna/MinaCalc/MinaCalc.cpp +++ b/src/Etterna/MinaCalc/MinaCalc.cpp @@ -942,6 +942,7 @@ MinaSDCalcDebug( * we have to write out after loading the values player defined, so the * quick hack solution to do that is to only do it during debug output * generation, which is fine for the time being, though not ideal */ + FILEMAN->FlushDirCache(calc.ulbu_in_charge->get_calc_param_xml()); if (!DoesFileExist(calc.ulbu_in_charge->get_calc_param_xml())) { calc.ulbu_in_charge->write_params_to_disk(); } diff --git a/src/Etterna/MinaCalc/UlbuBase.h b/src/Etterna/MinaCalc/UlbuBase.h index 199707dd7b..e8080ca144 100644 --- a/src/Etterna/MinaCalc/UlbuBase.h +++ b/src/Etterna/MinaCalc/UlbuBase.h @@ -328,10 +328,9 @@ struct Bazoinkazoink /// load custom xml parameters void load_calc_params_from_disk(bool bForce = false) const { const auto fn = get_calc_param_xml(); - int iError; // Hold calc params program-global persistent info - thread_local RageFileBasic* pFile; + thread_local RageFile* pFile; thread_local XNode params; // Only ever try to load params once per thread unless forcing thread_local bool paramsLoaded = false; @@ -342,17 +341,18 @@ struct Bazoinkazoink return; // Load if missing - if (pFile == nullptr || bForce) { + if (pFile == nullptr || bForce || !pFile->IsOpen()) { delete pFile; - pFile = FILEMAN->Open(fn, RageFile::READ, iError); + pFile = new RageFile(); // Failed to load - if (pFile == nullptr) + if (!pFile->Open(fn, RageFile::READ)) return; } // If it isn't loaded or we are forcing a load, load it if (params.ChildrenEmpty() || bForce) { if (!XmlFileUtil::LoadFromFileShowErrors(params, *pFile)) { + pFile->Close(); return; } } @@ -366,6 +366,7 @@ struct Bazoinkazoink paramsLoaded = true; load_calc_params_internal(params); + pFile->Close(); } /// save default xml parameters @@ -379,6 +380,7 @@ struct Bazoinkazoink return; } XmlFileUtil::SaveToFile(xml.get(), f, "", false); + f.Close(); } static auto make_mod_param_node(