From e3369aff83e3a55440564d3e4738449821a309d0 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Sat, 13 Jan 2018 17:27:21 +0500 Subject: Fixed segfault on connecting to server --- src/GlobalState.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/GlobalState.cpp b/src/GlobalState.cpp index a9f3d4e..80a3342 100644 --- a/src/GlobalState.cpp +++ b/src/GlobalState.cpp @@ -38,12 +38,18 @@ void InitEvents() { } LOG(INFO) << "Connecting to server"; PUSH_EVENT("Connecting",0); + gs = std::make_unique(); + isPhysRunning = true; + threadPhys = std::thread(&PhysExec); try { nc = std::make_unique(std::get<0>(data), std::get<1>(data), std::get<2>(data)); } catch (std::exception &e) { LOG(WARNING) << "Connection failed"; PUSH_EVENT("ConnectionFailed", std::string(e.what())); + isPhysRunning = false; + threadPhys.join(); + gs.reset(); return; } LOG(INFO) << "Connected to server"; @@ -70,12 +76,6 @@ void InitEvents() { isRunning = false; }); - listener.RegisterHandler("ConnectionSuccessfull", [](const Event&) { - gs = std::make_unique(); - isPhysRunning = true; - threadPhys = std::thread(&PhysExec); - }); - listener.RegisterHandler("Disconnected", [](const Event&) { if (!gs) return; -- cgit v1.2.3