Assert screen closed on destroy
The destruction order is important, but tricky, because the screen is open/close by the decoder, but destroyed by scrcpy.c on the main thread. Add assertions to guarantee that the screen is not destroyed before being closed.
This commit is contained in:
parent
2a94a2b119
commit
0272e6dc77
2 changed files with 17 additions and 0 deletions
|
@ -247,6 +247,9 @@ static bool
|
||||||
screen_frame_sink_open(struct sc_frame_sink *sink) {
|
screen_frame_sink_open(struct sc_frame_sink *sink) {
|
||||||
struct screen *screen = DOWNCAST(sink);
|
struct screen *screen = DOWNCAST(sink);
|
||||||
(void) screen;
|
(void) screen;
|
||||||
|
#ifndef NDEBUG
|
||||||
|
screen->open = true;
|
||||||
|
#endif
|
||||||
|
|
||||||
// nothing to do, the screen is already open on the main thread
|
// nothing to do, the screen is already open on the main thread
|
||||||
return true;
|
return true;
|
||||||
|
@ -256,6 +259,9 @@ static void
|
||||||
screen_frame_sink_close(struct sc_frame_sink *sink) {
|
screen_frame_sink_close(struct sc_frame_sink *sink) {
|
||||||
struct screen *screen = DOWNCAST(sink);
|
struct screen *screen = DOWNCAST(sink);
|
||||||
(void) screen;
|
(void) screen;
|
||||||
|
#ifndef NDEBUG
|
||||||
|
screen->open = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
// nothing to do, the screen lifecycle is not managed by the frame producer
|
// nothing to do, the screen lifecycle is not managed by the frame producer
|
||||||
}
|
}
|
||||||
|
@ -435,6 +441,10 @@ screen_init(struct screen *screen, struct fps_counter *fps_counter,
|
||||||
|
|
||||||
screen->frame_sink.ops = &ops;
|
screen->frame_sink.ops = &ops;
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
screen->open = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -445,6 +455,9 @@ screen_show_window(struct screen *screen) {
|
||||||
|
|
||||||
void
|
void
|
||||||
screen_destroy(struct screen *screen) {
|
screen_destroy(struct screen *screen) {
|
||||||
|
#ifndef NDEBUG
|
||||||
|
assert(!screen->open);
|
||||||
|
#endif
|
||||||
av_frame_free(&screen->frame);
|
av_frame_free(&screen->frame);
|
||||||
SDL_DestroyTexture(screen->texture);
|
SDL_DestroyTexture(screen->texture);
|
||||||
SDL_DestroyRenderer(screen->renderer);
|
SDL_DestroyRenderer(screen->renderer);
|
||||||
|
|
|
@ -15,6 +15,10 @@
|
||||||
struct screen {
|
struct screen {
|
||||||
struct sc_frame_sink frame_sink; // frame sink trait
|
struct sc_frame_sink frame_sink; // frame sink trait
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
bool open; // track the open/close state to assert correct behavior
|
||||||
|
#endif
|
||||||
|
|
||||||
struct video_buffer vb;
|
struct video_buffer vb;
|
||||||
struct fps_counter *fps_counter;
|
struct fps_counter *fps_counter;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue