Fix segfault on SDL event without window

Since #5804, controls have been enabled even with --no-window. As a
result, the Android clipboard is synchronized with the computer, causing
SDL to trigger an SDL_CLIPBOARDUPDATE event.

This event is ignored by scrcpy, but it was still transmitted to the
sc_screen instance, even if it had not been initialized.

Fix the issue by calling sc_screen_handle_event() only when a screen
instance exists.

Refs #5804 <https://github.com/Genymobile/scrcpy/pull/5804>
Fixes #5970 <https://github.com/Genymobile/scrcpy/issues/5970>
This commit is contained in:
Romain Vimont 2025-04-03 08:04:11 +02:00
commit 882003f314

View file

@ -165,7 +165,7 @@ sdl_configure(bool video_playback, bool disable_screensaver) {
} }
static enum scrcpy_exit_code static enum scrcpy_exit_code
event_loop(struct scrcpy *s) { event_loop(struct scrcpy *s, bool has_screen) {
SDL_Event event; SDL_Event event;
while (SDL_WaitEvent(&event)) { while (SDL_WaitEvent(&event)) {
switch (event.type) { switch (event.type) {
@ -197,7 +197,7 @@ event_loop(struct scrcpy *s) {
break; break;
} }
default: default:
if (!sc_screen_handle_event(&s->screen, &event)) { if (has_screen && !sc_screen_handle_event(&s->screen, &event)) {
return SCRCPY_EXIT_FAILURE; return SCRCPY_EXIT_FAILURE;
} }
break; break;
@ -933,7 +933,7 @@ aoa_complete:
} }
} }
ret = event_loop(s); ret = event_loop(s, options->window);
terminate_event_loop(); terminate_event_loop();
LOGD("quit..."); LOGD("quit...");