From a90221d924ff4a02d9f76c58471092ba0090b6d1 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sat, 30 Mar 2024 10:50:02 +0400 Subject: [PATCH] Fix crash when stopping screencast session twice --- src/dbus/mutter_screen_cast.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/dbus/mutter_screen_cast.rs b/src/dbus/mutter_screen_cast.rs index 853fe4aea..9c7ffb282 100644 --- a/src/dbus/mutter_screen_cast.rs +++ b/src/dbus/mutter_screen_cast.rs @@ -27,6 +27,7 @@ pub struct Session { to_niri: calloop::channel::Sender, #[allow(clippy::type_complexity)] streams: Arc)>>>, + stopped: Arc, } #[derive(Debug, Default, Deserialize, Type, Clone, Copy)] @@ -135,6 +136,11 @@ impl Session { ) { debug!("stop"); + if self.stopped.swap(true, Ordering::SeqCst) { + // Already stopped. + return; + } + Session::closed(&ctxt).await.unwrap(); if let Err(err) = self.to_niri.send(ScreenCastToNiri::StopCast { @@ -255,6 +261,7 @@ impl Session { ipc_outputs, streams: Arc::new(Mutex::new(vec![])), to_niri, + stopped: Arc::new(AtomicBool::new(false)), } } }