Skip to content

Commit

Permalink
stop holding the calcparam xml file handle forever
Browse files Browse the repository at this point in the history
  • Loading branch information
poco0317 committed Sep 25, 2024
1 parent 969196d commit 6bcb6e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Etterna/MinaCalc/MinaCalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
12 changes: 7 additions & 5 deletions src/Etterna/MinaCalc/UlbuBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
Expand All @@ -366,6 +366,7 @@ struct Bazoinkazoink
paramsLoaded = true;

load_calc_params_internal(params);
pFile->Close();
}

/// save default xml parameters
Expand All @@ -379,6 +380,7 @@ struct Bazoinkazoink
return;
}
XmlFileUtil::SaveToFile(xml.get(), f, "", false);
f.Close();
}

static auto make_mod_param_node(
Expand Down

0 comments on commit 6bcb6e5

Please sign in to comment.