From 7172cfd88974518e58e28f226b3a238bba2bd1c2 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 14 Jan 2021 19:28:21 -0600 Subject: [PATCH] Properly handle multiple window event flush barriers in flight at once Fixes streaming on macOS Mojave without Metal support --- app/streaming/session.cpp | 13 +++++++++---- app/streaming/session.h | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/streaming/session.cpp b/app/streaming/session.cpp index 261e4423..773a6b70 100644 --- a/app/streaming/session.cpp +++ b/app/streaming/session.cpp @@ -380,7 +380,7 @@ Session::Session(NvComputer* computer, NvApp& app, StreamingPreferences *prefere m_InputHandler(nullptr), m_InputHandlerLock(0), m_MouseEmulationRefCount(0), - m_FlushingWindowEvents(false), + m_FlushingWindowEventsRef(0), m_AsyncConnectionSuccess(false), m_PortTestResults(0), m_OpusDecoder(nullptr), @@ -1113,7 +1113,7 @@ void Session::flushWindowEvents() // Insert a barrier to discard any additional window events. // We don't use SDL_FlushEvent() here because it could cause // important events to be lost. - m_FlushingWindowEvents = true; + m_FlushingWindowEventsRef++; // This event will cause us to set m_FlushingWindowEvents back to false. SDL_Event flushEvent = {}; @@ -1343,7 +1343,7 @@ void Session::exec(int displayOriginX, int displayOriginY) SDL_ShowCursor(SDL_ENABLE); break; case SDL_CODE_FLUSH_WINDOW_EVENT_BARRIER: - m_FlushingWindowEvents = false; + m_FlushingWindowEventsRef--; break; default: SDL_assert(false); @@ -1401,8 +1401,13 @@ void Session::exec(int displayOriginX, int displayOriginY) SDL_SetWindowPosition(m_Window, x, y); } - if (m_FlushingWindowEvents) { + if (m_FlushingWindowEventsRef > 0) { // Ignore window events for renderer reset if flushing + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, + "Dropping window event during flush: %d (%d %d)", + event.window.event, + event.window.data1, + event.window.data2); break; } diff --git a/app/streaming/session.h b/app/streaming/session.h index 77602810..f372a651 100644 --- a/app/streaming/session.h +++ b/app/streaming/session.h @@ -152,7 +152,7 @@ private: SdlInputHandler* m_InputHandler; SDL_SpinLock m_InputHandlerLock; int m_MouseEmulationRefCount; - bool m_FlushingWindowEvents; + int m_FlushingWindowEventsRef; bool m_AsyncConnectionSuccess; int m_PortTestResults;