1
0
mirror of synced 2024-11-27 17:10:51 +01:00

fix: ImHex should crash less often now when exiting

This commit is contained in:
WerWolv 2021-07-31 17:11:10 +02:00
parent e8d77f8269
commit d345508195
5 changed files with 47 additions and 3 deletions

1
.gitignore vendored
View File

@ -4,6 +4,7 @@
cmake-build-debug/
cmake-build-release/
cmake-build-relwithdebinfo/
cmake-build-wsl/
build-linux/
build/

View File

@ -47,6 +47,10 @@ namespace hex {
SharedData::sharedVariables[variableName] = value;
}
static void clearVariables() {
SharedData::sharedVariables.clear();
}
public:
static std::vector<std::function<void()>> deferredCalls;
static prv::Provider *currentProvider;

View File

@ -10,14 +10,19 @@ namespace hex {
/* Settings */
void ContentRegistry::Settings::load() {
bool loaded = false;
for (const auto &dir : hex::getPath(ImHexPath::Config)) {
std::ifstream settingsFile(dir + "/settings.json");
if (settingsFile.good()) {
settingsFile >> getSettingsData();
loaded = true;
break;
}
}
if (!loaded)
ContentRegistry::Settings::store();
}
void ContentRegistry::Settings::store() {

View File

@ -2,7 +2,7 @@
namespace hex {
std::map<void*, EventManager::EventList::iterator> EventManager::s_tokenStore;
EventManager::EventList EventManager::s_events;
std::map<void*, EventManager::EventList::iterator> EventManager::s_tokenStore;
}

View File

@ -98,11 +98,45 @@ namespace hex::init {
return true;
}
bool deleteViews() {
bool deleteSharedData() {
SharedData::deferredCalls.clear();
delete SharedData::currentProvider;
SharedData::currentProvider = nullptr;
SharedData::settingsEntries.clear();
SharedData::settingsJson.clear();
SharedData::commandPaletteCommands.clear();
SharedData::patternLanguageFunctions.clear();
for (auto &view : SharedData::views)
delete view;
SharedData::views.clear();
SharedData::toolsEntries.clear();
SharedData::dataInspectorEntries.clear();
SharedData::bookmarkEntries.clear();
for (auto &pattern : SharedData::patternData)
delete pattern;
SharedData::patternData.clear();
SharedData::languageNames.clear();
SharedData::languageDefinitions.clear();
SharedData::loadedLanguageStrings.clear();
SharedData::welcomeScreenEntries.clear();
SharedData::footerItems.clear();
SharedData::dataProcessorNodes.clear();
SharedData::recentFilePaths.clear();
SharedData::clearVariables();
return true;
}
@ -160,8 +194,8 @@ namespace hex::init {
std::vector<Task> getExitTasks() {
return {
{ "Cleaning up views...", deleteViews },
{ "Saving settings...", storeSettings },
{ "Cleaning up shared data...", deleteSharedData },
{ "Unloading plugins...", unloadPlugins },
};
}