From 0541f1bff2be8dcf4de0765ce357836c0b2bf4ca Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Tue, 13 Apr 2021 22:22:54 +0200 Subject: [PATCH] Hide the window immediately on close The screen may not be destroyed immediately on close to avoid undefined behavior, because it may still receive events from the decoder. But the visual window must still be closed immediately. --- app/src/scrcpy.c | 4 ++++ app/src/screen.c | 5 +++++ app/src/screen.h | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index cab63522..4de62389 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -398,6 +398,10 @@ scrcpy(const struct scrcpy_options *options) { ret = event_loop(options); LOGD("quit..."); + // Close the window immediately on closing, because screen_destroy() may + // only be called once the stream thread is joined (it may take time) + screen_hide_window(&screen); + end: // The stream is not stopped explicitly, because it will stop by itself on // end-of-stream diff --git a/app/src/screen.c b/app/src/screen.c index 1b3c5179..0598ccf4 100644 --- a/app/src/screen.c +++ b/app/src/screen.c @@ -453,6 +453,11 @@ screen_show_window(struct screen *screen) { SDL_ShowWindow(screen->window); } +void +screen_hide_window(struct screen *screen) { + SDL_HideWindow(screen->window); +} + void screen_destroy(struct screen *screen) { #ifndef NDEBUG diff --git a/app/src/screen.h b/app/src/screen.h index 4a0bad09..2921c701 100644 --- a/app/src/screen.h +++ b/app/src/screen.h @@ -73,6 +73,13 @@ screen_init(struct screen *screen, struct fps_counter *fps_counter, void screen_destroy(struct screen *screen); +// hide the window +// +// It is used to hide the window immediately on closing without waiting for +// screen_destroy() +void +screen_hide_window(struct screen *screen); + // render the texture to the renderer // // Set the update_content_rect flag if the window or content size may have