From bc299928ad5571300180eb8edb6742ed3bbf0282 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 9 Oct 2024 00:26:40 +0100 Subject: [PATCH] output/xdg-output: avoid sending events to released globals ref #6835 --- src/protocols/XDGOutput.cpp | 4 +++- src/protocols/XDGOutput.hpp | 2 ++ src/protocols/core/Output.cpp | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/protocols/XDGOutput.cpp b/src/protocols/XDGOutput.cpp index 0cdadd43..0598e713 100644 --- a/src/protocols/XDGOutput.cpp +++ b/src/protocols/XDGOutput.cpp @@ -51,6 +51,8 @@ void CXDGOutputProtocol::onManagerGetXDGOutput(CZxdgOutputManagerV1* mgr, uint32 #endif pXDGOutput->client = CLIENT; + pXDGOutput->outputProto = OUTPUT->owner; + if (!pXDGOutput->resource->resource()) { m_vXDGOutputs.pop_back(); mgr->noMemory(); @@ -104,7 +106,7 @@ CXDGOutput::CXDGOutput(SP resource_, SP monitor_) : mon void CXDGOutput::sendDetails() { static auto PXWLFORCESCALEZERO = CConfigValue("xwayland:force_zero_scaling"); - if (!monitor) + if (!monitor || !outputProto || outputProto->isDefunct()) return; const auto POS = isXWayland ? monitor->vecXWaylandPosition : monitor->vecPosition; diff --git a/src/protocols/XDGOutput.hpp b/src/protocols/XDGOutput.hpp index 15d86cc7..520f3aaa 100644 --- a/src/protocols/XDGOutput.hpp +++ b/src/protocols/XDGOutput.hpp @@ -6,6 +6,7 @@ class CMonitor; class CXDGOutputProtocol; +class CWLOutputProtocol; class CXDGOutput { public: @@ -16,6 +17,7 @@ class CXDGOutput { private: WP monitor; SP resource; + WP outputProto; std::optional overridePosition; diff --git a/src/protocols/core/Output.cpp b/src/protocols/core/Output.cpp index 7b88e0a8..4047774a 100644 --- a/src/protocols/core/Output.cpp +++ b/src/protocols/core/Output.cpp @@ -47,7 +47,7 @@ SP CWLOutputResource::getResource() { } void CWLOutputResource::updateState() { - if (!monitor || (owner && owner->defunct)) + if (!monitor || !owner || owner->defunct) return; if (resource->version() >= 2) @@ -119,6 +119,9 @@ bool CWLOutputProtocol::isDefunct() { } void CWLOutputProtocol::sendDone() { + if (defunct) + return; + for (auto const& r : m_vOutputs) { r->resource->sendDone(); }