From d2a7e22efdc16b9ebe4b2f62b32bab8d6b6d03c5 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 17 Nov 2022 21:52:45 +0000 Subject: [PATCH] more memory safety around onDisconnect --- src/helpers/Monitor.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 6849c227..35ed9c2f 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -187,10 +187,8 @@ void CMonitor::onDisconnect() { return; } - const auto BACKUPWORKSPACE = BACKUPMON->activeWorkspace > 0 ? std::to_string(BACKUPMON->activeWorkspace) : "name:" + g_pCompositor->getWorkspaceByID(BACKUPMON->activeWorkspace)->m_szName; - // snap cursor - wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, BACKUPMON->vecPosition.x + BACKUPMON->vecTransformedSize.x / 2.f, BACKUPMON->vecPosition.y + BACKUPMON->vecTransformedSize.y / 2.f); + wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, BACKUPMON->vecPosition.x + BACKUPMON->vecTransformedSize.x / 2.f, BACKUPMON->vecPosition.y + BACKUPMON->vecTransformedSize.y / 2.f); // move workspaces std::deque wspToMove; @@ -215,13 +213,13 @@ void CMonitor::onDisconnect() { wlr_output_commit(output); - g_pCompositor->m_vWorkspaces.erase(std::remove_if(g_pCompositor->m_vWorkspaces.begin(), g_pCompositor->m_vWorkspaces.end(), [&](std::unique_ptr& el) { return el->m_iMonitorID == ID; })); + std::erase_if(g_pCompositor->m_vWorkspaces, [&](std::unique_ptr& el) { return el->m_iMonitorID == ID; }); Debug::log(LOG, "Removed monitor %s!", szName.c_str()); g_pEventManager->postEvent(SHyprIPCEvent{"monitorremoved", szName}); - g_pCompositor->m_vMonitors.erase(std::remove_if(g_pCompositor->m_vMonitors.begin(), g_pCompositor->m_vMonitors.end(), [&](std::shared_ptr& el) { return el.get() == this; })); + std::erase_if(g_pCompositor->m_vMonitors, [&](std::shared_ptr& el) { return el.get() == this; }); } void CMonitor::addDamage(pixman_region32_t* rg) {