diff --git a/host/platform/Windows/capture/NVFBC/src/nvfbc.c b/host/platform/Windows/capture/NVFBC/src/nvfbc.c index 2958f0f3..0720d82c 100644 --- a/host/platform/Windows/capture/NVFBC/src/nvfbc.c +++ b/host/platform/Windows/capture/NVFBC/src/nvfbc.c @@ -211,17 +211,8 @@ static void nvfbc_stop(void) { this->stop = true; - if (this->cursorEvents[0]) - { - lgSignalEvent(this->cursorEvents[0]); - this->cursorEvents[0] = NULL; - } - - if (this->frameEvent) - { - lgSignalEvent(this->frameEvent); - this->frameEvent = NULL; - } + lgSignalEvent(this->cursorEvents[0]); + lgSignalEvent(this->frameEvent); if (this->pointerThread) { diff --git a/host/platform/Windows/src/mousehook.c b/host/platform/Windows/src/mousehook.c index 82a9e618..6a80f2a2 100644 --- a/host/platform/Windows/src/mousehook.c +++ b/host/platform/Windows/src/mousehook.c @@ -146,6 +146,7 @@ void mouseHook_remove(void) { if (!mouseHook.event) return; + SetEvent(mouseHook.event); WaitForSingleObject(mouseHook.thread, INFINITE); CloseHandle(mouseHook.thread); diff --git a/host/platform/Windows/src/platform.c b/host/platform/Windows/src/platform.c index ddaa6a49..c7f92d68 100644 --- a/host/platform/Windows/src/platform.c +++ b/host/platform/Windows/src/platform.c @@ -146,7 +146,6 @@ static int appThread(void * opaque) int result = app_main(app.argc, app.argv); Shell_NotifyIcon(NIM_DELETE, &app.iconData); - mouseHook_remove(); SendMessage(app.messageWnd, WM_DESTROY, 0, 0); return result; } diff --git a/host/src/app.c b/host/src/app.c index 72e8cd45..92d3021e 100644 --- a/host/src/app.c +++ b/host/src/app.c @@ -275,14 +275,12 @@ static bool captureStart(void) DEBUG_INFO("Capture Size : %u MiB (%u)", maxFrameSize / 1048576, maxFrameSize); DEBUG_INFO("==== [ Capture Start ] ===="); - return startThreads(); + return true; } static bool captureStop(void) { DEBUG_INFO("==== [ Capture Stop ] ===="); - if (!stopThreads()) - return false; if (!app.iface->deinit()) { @@ -293,11 +291,6 @@ static bool captureStop(void) return true; } -static bool captureRestart(void) -{ - return captureStop() && captureStart(); -} - bool captureGetPointerBuffer(void ** data, uint32_t * size) { PLGMPMemory mem = app.pointerMemory[app.pointerIndex]; @@ -570,6 +563,10 @@ int app_main(int argc, char * argv[]) if (!lgCreateTimer(100, lgmpTimer, NULL, &app.lgmpTimer)) { DEBUG_ERROR("Failed to create the LGMP timer"); + + iface->deinit(); + iface->free(); + goto fail_timer; } @@ -583,6 +580,12 @@ int app_main(int argc, char * argv[]) exitcode = LG_HOST_EXIT_FAILED; goto fail_capture; } + + if (!startThreads()) + { + exitcode = LG_HOST_EXIT_FAILED; + goto fail_threads; + } } else { @@ -596,12 +599,30 @@ int app_main(int argc, char * argv[]) { if (app.state == APP_STATE_RESTART) { - if (!captureRestart()) + if (!stopThreads()) + { + exitcode = LG_HOST_EXIT_FAILED; + goto fail_threads; + } + + if (!captureStop()) { exitcode = LG_HOST_EXIT_FAILED; - stopThreads(); goto fail_capture; } + + if (!captureStart()) + { + exitcode = LG_HOST_EXIT_FAILED; + goto fail_capture; + } + + if (!startThreads()) + { + exitcode = LG_HOST_EXIT_FAILED; + goto fail_threads; + } + app.state = APP_STATE_RUNNING; } @@ -632,12 +653,32 @@ int app_main(int argc, char * argv[]) } if (app.state != APP_STATE_SHUTDOWN) + { DEBUG_INFO("No subscribers, going to sleep..."); - captureStop(); + if (!stopThreads()) + { + exitcode = LG_HOST_EXIT_FAILED; + goto fail_threads; + } + + if (!captureStop()) + { + exitcode = LG_HOST_EXIT_FAILED; + goto fail_capture; + } + + continue; + } + + break; } exitcode = app.exitcode; + stopThreads(); + +fail_threads: + captureStop(); fail_capture: lgTimerDestroy(app.lgmpTimer); @@ -645,9 +686,6 @@ fail_capture: fail_timer: LG_LOCK_FREE(app.pointerLock); - iface->deinit(); - iface->free(); - fail_lgmp: for(int i = 0; i < LGMP_Q_FRAME_LEN; ++i) lgmpHostMemFree(&app.frameMemory[i]);