[Client] Ensure mwmp::Main is initialized before GUIController cleanup

Previously, certain errors early in the program's execution – such as an attempt to use two different packet processors for the same packet ID – would not be displayed because of a crash when attempting to get an uninitialized mwmp::Main in the Engine's destructor.
pull/556/head
David Cernat 5 years ago
parent 5b4db83d61
commit 270867a397

@ -345,9 +345,11 @@ OMW::Engine::~Engine()
/* /*
Start of tes3mp addition Start of tes3mp addition
Free up memory allocated by multiplayer's GUIController Free up memory allocated by multiplayer's GUIController, but make sure
mwmp::Main has actually been initialized
*/ */
mwmp::Main::get().getGUIController()->cleanUp(); if (mwmp::Main::isInitialized())
mwmp::Main::get().getGUIController()->cleanUp();
/* /*
End of tes3mp addition End of tes3mp addition
*/ */

@ -163,6 +163,11 @@ void Main::postInit()
MWBase::Environment::get().getMechanicsManager()->toggleAI(); MWBase::Environment::get().getMechanicsManager()->toggleAI();
} }
bool Main::isInitialized()
{
return pMain != nullptr;
}
void Main::destroy() void Main::destroy()
{ {
assert(pMain); assert(pMain);

@ -23,6 +23,7 @@ namespace mwmp
static void configure(const boost::program_options::variables_map &variables); static void configure(const boost::program_options::variables_map &variables);
static bool init(std::vector<std::string> &content, Files::Collections &collections); static bool init(std::vector<std::string> &content, Files::Collections &collections);
static void postInit(); static void postInit();
static bool isInitialized();
static void destroy(); static void destroy();
static const Main &get(); static const Main &get();
static void frame(float dt); static void frame(float dt);

Loading…
Cancel
Save