Use the async connect thread on all platforms

It turned out that the cause of the random crashes was the threaded renderer
that we now turn off.
This commit is contained in:
Cameron Gutman 2021-02-06 15:14:15 -06:00
parent 90f7d35150
commit e4df70cd56

View file

@ -37,14 +37,6 @@
#define CONN_TEST_SERVER "qt.conntest.moonlight-stream.org" #define CONN_TEST_SERVER "qt.conntest.moonlight-stream.org"
// Running the connection process asynchronously seems to reliably
// cause a crash in QSGRenderThread on Wayland and strange crashes
// elsewhere. Until these are figured out, avoid the async connect
// thread on Linux and BSDs.
#if !defined(Q_OS_UNIX) || defined(Q_OS_DARWIN)
#define USE_ASYNC_CONNECT_THREAD 1
#endif
CONNECTION_LISTENER_CALLBACKS Session::k_ConnCallbacks = { CONNECTION_LISTENER_CALLBACKS Session::k_ConnCallbacks = {
Session::clStageStarting, Session::clStageStarting,
nullptr, nullptr,
@ -65,11 +57,6 @@ void Session::clStageStarting(int stage)
// which happens to be the main thread, so it's cool to interact // which happens to be the main thread, so it's cool to interact
// with the GUI in these callbacks. // with the GUI in these callbacks.
emit s_ActiveSession->stageStarting(QString::fromLocal8Bit(LiGetStageName(stage))); emit s_ActiveSession->stageStarting(QString::fromLocal8Bit(LiGetStageName(stage)));
#ifndef USE_ASYNC_CONNECT_THREAD
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
QCoreApplication::sendPostedEvents();
#endif
} }
void Session::clStageFailed(int stage, int errorCode) void Session::clStageFailed(int stage, int errorCode)
@ -81,11 +68,6 @@ void Session::clStageFailed(int stage, int errorCode)
char failingPorts[128]; char failingPorts[128];
LiStringifyPortFlags(portFlags, ", ", failingPorts, sizeof(failingPorts)); LiStringifyPortFlags(portFlags, ", ", failingPorts, sizeof(failingPorts));
emit s_ActiveSession->stageFailed(QString::fromLocal8Bit(LiGetStageName(stage)), errorCode, QString(failingPorts)); emit s_ActiveSession->stageFailed(QString::fromLocal8Bit(LiGetStageName(stage)), errorCode, QString(failingPorts));
#ifndef USE_ASYNC_CONNECT_THREAD
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
QCoreApplication::sendPostedEvents();
#endif
} }
void Session::clConnectionTerminated(int errorCode) void Session::clConnectionTerminated(int errorCode)
@ -1002,17 +984,7 @@ bool Session::startConnectionAsync()
{ {
// Wait 1.5 seconds before connecting to let the user // Wait 1.5 seconds before connecting to let the user
// have time to read any messages present on the segue // have time to read any messages present on the segue
#ifdef USE_ASYNC_CONNECT_THREAD
SDL_Delay(1500); SDL_Delay(1500);
#else
uint32_t start = SDL_GetTicks();
while (!SDL_TICKS_PASSED(SDL_GetTicks(), start + 1500)) {
// Pump the UI loop while we wait since we're not async
SDL_Delay(5);
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
QCoreApplication::sendPostedEvents();
}
#endif
// The UI should have ensured the old game was already quit // The UI should have ensured the old game was already quit
// if we decide to stream a different game. // if we decide to stream a different game.
@ -1154,15 +1126,11 @@ void Session::exec(int displayOriginX, int displayOriginY)
// Kick off the async connection thread while we sit here and pump the event loop // Kick off the async connection thread while we sit here and pump the event loop
AsyncConnectionStartThread asyncConnThread(this); AsyncConnectionStartThread asyncConnThread(this);
#ifdef USE_ASYNC_CONNECT_THREAD
asyncConnThread.start(); asyncConnThread.start();
while (!asyncConnThread.wait(10)) { while (!asyncConnThread.wait(10)) {
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
QCoreApplication::sendPostedEvents(); QCoreApplication::sendPostedEvents();
} }
#else
asyncConnThread.run();
#endif
// Pump the event loop one last time to ensure we pick up any events from // Pump the event loop one last time to ensure we pick up any events from
// the thread that happened while it was in the final successful QThread::wait(). // the thread that happened while it was in the final successful QThread::wait().