Moved the CollectionSystemsManager cleanup from the destructor to a deinit function.

This commit is contained in:
Leon Styhre 2022-01-04 23:14:12 +01:00
parent 87ace0b8cb
commit f8e201d347
3 changed files with 29 additions and 25 deletions

View file

@ -86,36 +86,37 @@ CollectionSystemsManager::CollectionSystemsManager() noexcept
mCustomCollectionsBundle = nullptr;
}
CollectionSystemsManager::~CollectionSystemsManager()
{
// Don't attempt to remove any collections if no systems exist.
if (SystemData::sSystemVector.size() > 0)
removeCollectionsFromDisplayedSystems();
// Delete all custom collections.
for (std::map<std::string, CollectionSystemData, stringComparator>::const_iterator it =
mCustomCollectionSystemsData.cbegin();
it != mCustomCollectionSystemsData.cend(); ++it)
delete it->second.system;
// Delete the custom collections bundle.
if (mCustomCollectionsBundle)
delete mCustomCollectionsBundle;
// Delete the auto collections systems.
for (auto it = mAutoCollectionSystemsData.cbegin(); // Line break.
it != mAutoCollectionSystemsData.cend(); ++it)
delete (*it).second.system;
delete mCollectionEnvData;
}
CollectionSystemsManager* CollectionSystemsManager::getInstance()
{
static CollectionSystemsManager instance;
return &instance;
}
void CollectionSystemsManager::deinit()
{
// Don't attempt to remove any collections if no systems exist.
if (SystemData::sSystemVector.size() > 0) {
removeCollectionsFromDisplayedSystems();
// Delete all custom collections.
for (std::map<std::string, CollectionSystemData, stringComparator>::const_iterator it =
mCustomCollectionSystemsData.cbegin();
it != mCustomCollectionSystemsData.cend(); ++it)
delete it->second.system;
// Delete the custom collections bundle.
if (mCustomCollectionsBundle)
delete mCustomCollectionsBundle;
// Delete the auto collections systems.
for (auto it = mAutoCollectionSystemsData.cbegin(); // Line break.
it != mAutoCollectionSystemsData.cend(); ++it)
delete (*it).second.system;
}
delete mCollectionEnvData;
}
void CollectionSystemsManager::saveCustomCollection(SystemData* sys)
{
const std::string rompath = FileData::getROMDirectory();

View file

@ -75,6 +75,9 @@ public:
static CollectionSystemsManager* getInstance();
void saveCustomCollection(SystemData* sys);
// Clean up all systems, called during application shutdown.
void deinit();
// Functions to load all collections into memory, and enable the active ones:
// Load all collection systems.
void loadCollectionSystems();
@ -133,7 +136,6 @@ public:
private:
CollectionSystemsManager() noexcept;
~CollectionSystemsManager();
SystemEnvironmentData* mCollectionEnvData;
std::map<std::string, CollectionSystemDecl, stringComparator> mCollectionSystemDeclsIndex;

View file

@ -683,6 +683,7 @@ int main(int argc, char* argv[])
delete window->peekGui();
window->deinit();
CollectionSystemsManager::getInstance()->deinit();
SystemData::deleteSystems();
NavigationSounds::getInstance().deinit();