From a31c6c4cd029e31c132aa415e3c33bc3915aaf9e Mon Sep 17 00:00:00 2001 From: Mathias Tillman Date: Wed, 9 Mar 2022 16:20:51 +0100 Subject: [PATCH 1/2] Fix hwdevice being destroyed before context, causing a sigsegv because the context relies on the hwdevice still being active. --- sunshine/video.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sunshine/video.cpp b/sunshine/video.cpp index b2a8858b..f435d507 100644 --- a/sunshine/video.cpp +++ b/sunshine/video.cpp @@ -324,7 +324,7 @@ struct encoder_t { class session_t { public: session_t() = default; - session_t(ctx_t &&ctx, std::shared_ptr &&device, int inject) : ctx { std::move(ctx) }, device { std::move(device) }, inject { inject } {} + session_t(ctx_t &&ctx, std::shared_ptr &&device, int inject) : device { std::move(device) }, ctx { std::move(ctx) }, inject { inject } {} session_t(session_t &&other) noexcept = default; @@ -341,8 +341,8 @@ public: return *this; } - ctx_t ctx; std::shared_ptr device; + ctx_t ctx; std::vector replacements; From 6fca2c593ceb21dafe71600ad536af6edfd02c60 Mon Sep 17 00:00:00 2001 From: Mathias Tillman Date: Thu, 10 Mar 2022 09:09:24 +0100 Subject: [PATCH 2/2] Use session_t destructor to ensure the context and hwdevice are always destroyed in the correct order. --- sunshine/video.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sunshine/video.cpp b/sunshine/video.cpp index f435d507..0f7eff35 100644 --- a/sunshine/video.cpp +++ b/sunshine/video.cpp @@ -324,9 +324,14 @@ struct encoder_t { class session_t { public: session_t() = default; - session_t(ctx_t &&ctx, std::shared_ptr &&device, int inject) : device { std::move(device) }, ctx { std::move(ctx) }, inject { inject } {} + session_t(ctx_t &&ctx, std::shared_ptr &&device, int inject) : ctx { std::move(ctx) }, device { std::move(device) }, inject { inject } {} session_t(session_t &&other) noexcept = default; + ~session_t() { + // Order matters here because the context relies on the hwdevice still being valid + ctx.reset(); + device.reset(); + } // Ensure objects are destroyed in the correct order session_t &operator=(session_t &&other) { @@ -341,8 +346,8 @@ public: return *this; } - std::shared_ptr device; ctx_t ctx; + std::shared_ptr device; std::vector replacements;