summaryrefslogtreecommitdiff
path: root/src/helpers/Monitor.cpp
diff options
context:
space:
mode:
authorvaxerski <vaxry@vaxry.net>2024-08-19 18:44:22 +0200
committervaxerski <vaxry@vaxry.net>2024-08-19 18:44:22 +0200
commitc86db7bbb0cf14d4955ee3a4d13c0ed9f8a0e0ae (patch)
treea20a91cd4835905a712647e660cd63b5ed903729 /src/helpers/Monitor.cpp
parent272d9048706379201b761c3159c24a20cd62fad1 (diff)
monitor: avoid dangling references to old monitors being undestroyed
ref #7414
Diffstat (limited to 'src/helpers/Monitor.cpp')
-rw-r--r--src/helpers/Monitor.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp
index 9542d2c4..2c6282e1 100644
--- a/src/helpers/Monitor.cpp
+++ b/src/helpers/Monitor.cpp
@@ -25,7 +25,7 @@ int ratHandler(void* data) {
return 1;
}
-CMonitor::CMonitor() : state(this) {
+CMonitor::CMonitor(SP<Aquamarine::IOutput> output_) : state(this), output(output_) {
;
}
@@ -40,16 +40,29 @@ void CMonitor::onConnect(bool noRule) {
outTimeline = CSyncTimeline::create(output->getBackend()->drmFD());
}
- listeners.frame = output->events.frame.registerListener([this](std::any d) { Events::listener_monitorFrame(this, nullptr); });
- listeners.destroy = output->events.destroy.registerListener([this](std::any d) { Events::listener_monitorDestroy(this, nullptr); });
- listeners.commit = output->events.commit.registerListener([this](std::any d) { Events::listener_monitorCommit(this, nullptr); });
+ listeners.frame = output->events.frame.registerListener([this](std::any d) { Events::listener_monitorFrame(this, nullptr); });
+ listeners.commit = output->events.commit.registerListener([this](std::any d) { Events::listener_monitorCommit(this, nullptr); });
listeners.needsFrame =
output->events.needsFrame.registerListener([this](std::any d) { g_pCompositor->scheduleFrameForMonitor(this, Aquamarine::IOutput::AQ_SCHEDULE_NEEDS_FRAME); });
+
listeners.presented = output->events.present.registerListener([this](std::any d) {
auto E = std::any_cast<Aquamarine::IOutput::SPresentEvent>(d);
PROTO::presentation->onPresented(this, E.when, E.refresh, E.seq, E.flags);
});
+ listeners.destroy = output->events.destroy.registerListener([this](std::any d) {
+ Debug::log(LOG, "Destroy called for monitor {}", szName);
+
+ onDisconnect(true);
+
+ output = nullptr;
+ m_bRenderingInitPassed = false;
+
+ Debug::log(LOG, "Removing monitor {} from realMonitors", szName);
+
+ std::erase_if(g_pCompositor->m_vRealMonitors, [&](SP<CMonitor>& el) { return el.get() == this; });
+ });
+
listeners.state = output->events.state.registerListener([this](std::any d) {
auto E = std::any_cast<Aquamarine::IOutput::SStateEvent>(d);