Skip to content

Commit e016451

Browse files
committed
Log SDL keybaord events as part of RUNTIME_DEBUG.
Also, test_sdl_key_test.c to test_interactive.py. This test was not being run anywhere else and serves as simple way to test/debug keyboard events. Also, only set the `RUNTIME_DEBUG` default if the user does not explicitly set it themselves. This allows for `-sSOCKETS_DEBUG -sRUNTIM_DEBUG=0` to opt out of the `RUNTIME_DEBUG` channel. Finally, disable the `RUNTIME_DEBUG` traces that occur during turns of the event loop unless `RUNTIME_DEBUG` is set to 2. This avoids flooding the console will messages in applications that are using the event loop.
1 parent c1540c3 commit e016451

File tree

6 files changed

+25
-17
lines changed

6 files changed

+25
-17
lines changed

src/library.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2160,7 +2160,7 @@ addToLibrary({
21602160
return;
21612161
}
21622162
#endif
2163-
#if RUNTIME_DEBUG
2163+
#if RUNTIME_DEBUG == 2
21642164
dbg(`maybeExit: user callback done: runtimeKeepaliveCounter=${runtimeKeepaliveCounter}`);
21652165
#endif
21662166
if (!keepRuntimeAlive()) {

src/library_sdl.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,9 @@ var LibrarySDL = {
930930
switch (event.type) {
931931
case 'keydown': case 'keyup': {
932932
var down = event.type === 'keydown';
933-
//dbg('Received key event: ' + event.keyCode);
933+
#if RUNTIME_DEBUG
934+
dbg(`received ${event.type} event: keyCode=${event.keyCode}, key=${event.key}, code=${event.code}`);
935+
#endif
934936
var key = SDL.lookupKeyCodeForEvent(event);
935937
var scan;
936938
if (key >= 1024) {

src/runtime_stack_check.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function checkStackCookie() {
3636
if (ABORT) return;
3737
#endif
3838
var max = _emscripten_stack_get_end();
39-
#if RUNTIME_DEBUG
39+
#if RUNTIME_DEBUG == 2
4040
dbg(`checkStackCookie: ${ptrToString(max)}`);
4141
#endif
4242
// See writeStackCookie().

src/settings.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,9 @@ var TRUSTED_TYPES = false;
21372137
// settings is *only* needed when also explicitly targeting older browsers.
21382138
var POLYFILL = true;
21392139

2140-
// If true, add tracing to core runtime functions.
2140+
// If non-zero, add tracing to core runtime functions. Can be set to 2 for
2141+
// extra tracing (for example, tracing that occors on each turn of the event
2142+
// loop or each user callback which can flood the console).
21412143
// This setting is enabled by default if any of the following debugging settings
21422144
// are enabled:
21432145
// - PTHREADS_DEBUG
@@ -2151,7 +2153,7 @@ var POLYFILL = true;
21512153
// - SOCKET_DEBUG
21522154
// - FETCH_DEBUG
21532155
// [link]
2154-
var RUNTIME_DEBUG = false;
2156+
var RUNTIME_DEBUG = 0;
21552157

21562158
// Include JS library symbols that were previously part of the default runtime.
21572159
// Without this, such symbols can be made available by adding them to

test/test_interactive.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ def test_sdl_touch(self):
4848
def test_sdl_wm_togglefullscreen(self):
4949
self.btest_exit('test_sdl_wm_togglefullscreen.c')
5050

51+
def test_sdl_key_test(self):
52+
self.btest_exit('test_sdl_key_test.c', args=['-sRUNTIME_DEBUG'])
53+
5154
def test_sdl_fullscreen_samecanvassize(self):
5255
self.btest_exit('test_sdl_fullscreen_samecanvassize.c')
5356

tools/link.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -666,18 +666,19 @@ def phase_linker_setup(options, state, newargs):
666666
if options.cpu_profiler:
667667
options.post_js.append(utils.path_from_root('src/cpuprofiler.js'))
668668

669-
if not settings.RUNTIME_DEBUG:
670-
settings.RUNTIME_DEBUG = bool(settings.LIBRARY_DEBUG or
671-
settings.GL_DEBUG or
672-
settings.DYLINK_DEBUG or
673-
settings.OPENAL_DEBUG or
674-
settings.SYSCALL_DEBUG or
675-
settings.WEBSOCKET_DEBUG or
676-
settings.SOCKET_DEBUG or
677-
settings.FETCH_DEBUG or
678-
settings.EXCEPTION_DEBUG or
679-
settings.PTHREADS_DEBUG or
680-
settings.ASYNCIFY_DEBUG)
669+
# Unless RUNTIME_DEBUG is explicitly set then we enable it when any of the
670+
# more specfic debug settings are present.
671+
default_setting('RUNTIME_DEBUG', int(settings.LIBRARY_DEBUG or
672+
settings.GL_DEBUG or
673+
settings.DYLINK_DEBUG or
674+
settings.OPENAL_DEBUG or
675+
settings.SYSCALL_DEBUG or
676+
settings.WEBSOCKET_DEBUG or
677+
settings.SOCKET_DEBUG or
678+
settings.FETCH_DEBUG or
679+
settings.EXCEPTION_DEBUG or
680+
settings.PTHREADS_DEBUG or
681+
settings.ASYNCIFY_DEBUG))
681682

682683
if options.memory_profiler:
683684
settings.MEMORYPROFILER = 1

0 commit comments

Comments
 (0)