From 6aa89934e8f22a580dc8a63cec61fb9ea9d14f23 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 3 Jul 2015 11:50:41 +0200 Subject: simconnect: prevent crash with no .dll --- ftnoir_protocol_sc/ftnoir_protocol_sc.cpp | 12 ++++++++---- ftnoir_protocol_sc/ftnoir_protocol_sc.h | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'ftnoir_protocol_sc') diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp index 41fcf1b0..8e35248e 100644 --- a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp +++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp @@ -31,7 +31,7 @@ static QLibrary SCClientLib; -FTNoIR_Protocol::FTNoIR_Protocol() : should_stop(false), hSimConnect(nullptr) +FTNoIR_Protocol::FTNoIR_Protocol() : should_stop(false), hSimConnect(nullptr), should_start(false) { start(); } @@ -40,13 +40,13 @@ FTNoIR_Protocol::~FTNoIR_Protocol() { should_stop = true; wait(); - - if (hSimConnect) - (void) simconnect_close(hSimConnect); } void FTNoIR_Protocol::run() { + if (!should_start) + return; + if (SUCCEEDED(simconnect_open(&hSimConnect, "FaceTrackNoIR", NULL, 0, 0, 0))) { simconnect_subscribetosystemevent(hSimConnect, EVENT_PING, "Frame"); @@ -62,6 +62,8 @@ void FTNoIR_Protocol::run() (void) (simconnect_calldispatch(hSimConnect, processNextSimconnectEvent, reinterpret_cast(this))); Sleep(3); } + + (void) simconnect_close(hSimConnect); } void FTNoIR_Protocol::pose( const double *headpose ) { @@ -182,6 +184,8 @@ bool FTNoIR_Protocol::correct() } qDebug() << "FTNoIR_Protocol::correct() says: SimConnect functions resolved in DLL!"; + + should_start = true; return true; } diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.h b/ftnoir_protocol_sc/ftnoir_protocol_sc.h index b65bac85..3ced16e5 100644 --- a/ftnoir_protocol_sc/ftnoir_protocol_sc.h +++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.h @@ -126,6 +126,8 @@ private: HANDLE hSimConnect; // Handle to SimConnect static void CALLBACK processNextSimconnectEvent(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext); settings s; + + bool should_start; }; class SCControls: public IProtocolDialog -- cgit v1.2.3