[Toast] Uninitialize if possible

This commit is contained in:
momo5502 2017-02-24 13:30:31 +01:00
parent d3ca680e7a
commit a3cb37f7e4
3 changed files with 45 additions and 7 deletions

View File

@ -12,6 +12,11 @@ namespace Components
return Loader::Pregame;
}
bool Loader::IsPostgame()
{
return Loader::Postgame;
}
void Loader::Initialize()
{
Loader::Pregame = true;
@ -93,7 +98,7 @@ namespace Components
void Loader::Uninitialize()
{
Loader::PreDestroy();
Loader::PreDestroyNoPostGame();
std::reverse(Loader::Components.begin(), Loader::Components.end());
for (auto component : Loader::Components)
@ -119,14 +124,32 @@ namespace Components
{
Loader::Postgame = true;
std::reverse(Loader::Components.begin(), Loader::Components.end());
for (auto component : Loader::Components)
auto components = Loader::Components;
std::reverse(components.begin(), components.end());
for (auto component : components)
{
component->preDestroy();
}
}
}
void Loader::PreDestroyNoPostGame()
{
if (!Loader::Postgame)
{
auto components = Loader::Components;
std::reverse(components.begin(), components.end());
for (auto component : components)
{
component->preDestroy();
}
Loader::Postgame = true;
}
}
bool Loader::PerformUnitTests()
{
bool result = true;

View File

@ -25,11 +25,13 @@ namespace Components
static void Initialize();
static void Uninitialize();
static void PreDestroy();
static void PreDestroyNoPostGame();
static bool PerformUnitTests();
static bool PerformingUnitTests();
static void Register(Component* component);
static bool IsPregame();
static bool IsPostgame();
static Utils::Memory::Allocator* GetAlloctor();

View File

@ -174,13 +174,26 @@ namespace Components
{
if (Dedicated::IsEnabled()) return;
// Destroying that on the main thread deadlocks, for whatever reason.
// Destroying that on the main thread deadlocks.
// I did not write the library, so whatever.
std::thread([]()
// If we are not in the postgame state,
// we are not allowed to spawn threads,
// so just don't uninitialize the library.
// That means we did not uninitialize the game
// correctly anyways.
if (Loader::IsPostgame())
{
std::thread([]()
{
delete WinToastLib::WinToast::instance();
delete Toast::ToastHandler;
Toast::ToastHandler = nullptr;
}).join();
}
else
{
delete WinToastLib::WinToast::instance();
delete Toast::ToastHandler;
Toast::ToastHandler = nullptr;
}).join();
}
}
}