Skip to content

Commit aa086e3

Browse files
past-dueKJeff01
authored andcommittedMar 11, 2018
[SDL backend] Do not call QCoreApplication::processEvents() on Windows or macOS
In SDL backend builds, the only thing that currently requires Qt's `QCoreApplication::processEvents()` is the script debugger window (which is built using Qt) - and only on non-Windows/macOS operating systems. Since the script debugger window works on Windows and macOS without `processEvents()`, do not call it on Windows and macOS builds. This fixes: - trac #4714 "can't take in-game screenshots anymore" (on Windows) - the need for a (somewhat crude) workaround on macOS - issues with keys getting "stuck" on macOS
1 parent 037f9d5 commit aa086e3

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed
 

‎lib/sdl/main_sdl.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,18 @@ void wzMainEventLoop(void)
21292129
break;
21302130
}
21312131
}
2132+
#if !defined(WZ_OS_WIN) && !defined(WZ_OS_MAC)
2133+
// Ideally, we don't want Qt processing events in addition to SDL - this causes
2134+
// all kinds of issues (crashes taking screenshots on Windows, freezing on
2135+
// macOS without a nasty workaround) - but without the following line the script
2136+
// debugger window won't display properly on Linux.
2137+
//
2138+
// Therefore, do not include it on Windows and macOS builds, which does not
2139+
// impact the script debugger's functionality, but include it (for now) on other
2140+
// builds until an alternative script debugger UI is available.
2141+
//
21322142
appPtr->processEvents(); // Qt needs to do its stuff
2143+
#endif
21332144
processScreenSizeChangeNotificationIfNeeded();
21342145
mainLoop(); // WZ does its thing
21352146
inputNewFrame(); // reset input states

‎src/main.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -848,10 +848,6 @@ int realmain(int argc, char *argv[])
848848
const char **utfargv = (const char **)argv;
849849
wzMain(argc, argv); // init Qt integration first
850850

851-
#ifdef WZ_OS_MAC
852-
cocoaInit();
853-
#endif
854-
855851
debug_init();
856852
debug_register_callback(debug_callback_stderr, nullptr, nullptr, nullptr);
857853
#if defined(WZ_OS_WIN) && defined(DEBUG_INSANE)
@@ -1106,12 +1102,7 @@ int realmain(int argc, char *argv[])
11061102
debug_MEMSTATS();
11071103
#endif
11081104
debug(LOG_MAIN, "Entering main loop");
1109-
#ifndef WZ_OS_MAC
11101105
wzMainEventLoop();
1111-
#else // WZ_OS_MAC
1112-
// On Mac, use special method of launching NSApplication properly
1113-
cocoaRunApplication(&wzMainEventLoop);
1114-
#endif
11151106
saveConfig();
11161107
systemShutdown();
11171108
#ifdef WZ_OS_WIN // clean up the memory allocated for the command line conversion

‎src/qtscript.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,9 @@ QScriptEngine *loadPlayerScript(const QString& path, int player, int difficulty)
602602
{
603603
ASSERT_OR_RETURN(nullptr, player < MAX_PLAYERS, "Player index %d out of bounds", player);
604604
QScriptEngine *engine = new QScriptEngine();
605+
// Set processEventsInterval to -1 because the interpreter should *never* call
606+
// QCoreApplication::processEvents() (or SDL builds will break in various ways).
607+
engine->setProcessEventsInterval(-1);
605608
UDWORD size;
606609
char *bytes = nullptr;
607610
if (!loadFile(path.toUtf8().constData(), &bytes, &size))

0 commit comments

Comments
 (0)