Skip to content

Commit 475eeda

Browse files
authored
Log SDL keyboard events as part of RUNTIME_DEBUG. (#22918)
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 6079640 commit 475eeda

File tree

9 files changed

+41
-23
lines changed

9 files changed

+41
-23
lines changed

site/source/docs/tools_reference/settings_reference.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3297,7 +3297,9 @@ Default value: true
32973297
RUNTIME_DEBUG
32983298
=============
32993299

3300-
If true, add tracing to core runtime functions.
3300+
If non-zero, add tracing to core runtime functions. Can be set to 2 for
3301+
extra tracing (for example, tracing that occurs on each turn of the event
3302+
loop or each user callback, which can flood the console).
33013303
This setting is enabled by default if any of the following debugging settings
33023304
are enabled:
33033305
- PTHREADS_DEBUG
@@ -3311,7 +3313,7 @@ are enabled:
33113313
- SOCKET_DEBUG
33123314
- FETCH_DEBUG
33133315

3314-
Default value: false
3316+
Default value: 0
33153317

33163318
.. _legacy_runtime:
33173319

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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,9 @@ var LibrarySDL = {
826826
if (code >= 65 && code <= 90) {
827827
code += 32; // make lowercase for SDL
828828
} else {
829+
#if RUNTIME_DEBUG
830+
if (!(event.keyCode in SDL.keyCodes)) dbg('unknown keyCode: ', event.keyCode);
831+
#endif
829832
code = SDL.keyCodes[event.keyCode] || event.keyCode;
830833
// If this is one of the modifier keys (224 | 1<<10 - 227 | 1<<10), and the event specifies that it is
831834
// a right key, add 4 to get the right key SDL key code.
@@ -931,7 +934,9 @@ var LibrarySDL = {
931934
switch (event.type) {
932935
case 'keydown': case 'keyup': {
933936
var down = event.type === 'keydown';
934-
//dbg('Received key event: ' + event.keyCode);
937+
#if RUNTIME_DEBUG
938+
dbg(`received ${event.type} event: keyCode=${event.keyCode}, key=${event.key}, code=${event.code}`);
939+
#endif
935940
var key = SDL.lookupKeyCodeForEvent(event);
936941
var scan;
937942
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 occurs 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/browser/test_sdl_key_proxy.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,28 @@ int result = 1;
1515
EMSCRIPTEN_KEEPALIVE void one() {
1616
SDL_Event event;
1717
while (SDL_PollEvent(&event)) {
18-
printf("got event %d\n", event.type);
19-
switch(event.type) {
18+
switch (event.type) {
2019
case SDL_KEYDOWN:
2120
break;
2221
case SDL_KEYUP:
2322
// don't handle the modifier key events
2423
if (event.key.keysym.sym == SDLK_LCTRL ||
2524
event.key.keysym.sym == SDLK_LSHIFT ||
2625
event.key.keysym.sym == SDLK_LALT) {
26+
printf("got modifier: %d\n", event.key.keysym.sym);
2727
return;
2828
}
29+
printf("got SDL_KEYUP: ");
2930
if ((event.key.keysym.mod & KMOD_LCTRL) || (event.key.keysym.mod & KMOD_RCTRL)) {
31+
printf("CTRL + ");
3032
result *= 2;
3133
}
3234
if ((event.key.keysym.mod & KMOD_LSHIFT) || (event.key.keysym.mod & KMOD_RSHIFT)) {
35+
printf("SHIFT + ");
3336
result *= 3;
3437
}
3538
if ((event.key.keysym.mod & KMOD_LALT) || (event.key.keysym.mod & KMOD_RALT)) {
39+
printf("ALT + ");
3640
result *= 5;
3741
}
3842
switch (event.key.keysym.sym) {
@@ -52,7 +56,8 @@ EMSCRIPTEN_KEEPALIVE void one() {
5256
}
5357
break;
5458
default: /* Report an unhandled event */
55-
printf("I don't know what this event is!\n");
59+
printf("I don't know what this event is! (%d)\n", event.type);
60+
emscripten_force_exit(1);
5661
}
5762
}
5863
}

test/test_browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ def post():
10011001
</body>''')
10021002
create_file('test.html', html)
10031003

1004-
self.btest_exit('test_sdl_key_proxy.c', 223092870, args=['--proxy-to-worker', '--pre-js', 'pre.js', '-lSDL', '-lGL'], post_build=post)
1004+
self.btest_exit('test_sdl_key_proxy.c', 223092870, args=['--proxy-to-worker', '--pre-js', 'pre.js', '-lSDL', '-lGL', '-sRUNTIME_DEBUG'], post_build=post)
10051005

10061006
def test_canvas_focus(self):
10071007
self.btest_exit('canvas_focus.c')

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)