From b7516cac5b37b644d159966d710460a2ef2b1627 Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Mon, 3 Jun 2024 21:07:36 +0200 Subject: [PATCH] Fix crash when adding resources to resources tab A crash could occur if the plugin window was closed and reopened and a new resource was added to either the Variable, Action queue, Websocket, or Twitch tab. No context object was provided to the signal handlers. The signal provider is intentionally not deleted when the UI is closed. Because of this, the signal connections were never cleared when the underlying tab widget was destroyed. So, in the case of closing and reopening the settings window, the old connection with the outdated widget pointers would be called again. --- lib/queue/action-queue-tab.cpp | 7 ++++--- lib/variables/variable-tab.cpp | 6 +++--- plugins/base/utils/websocket-tab.cpp | 6 +++--- plugins/twitch/twitch-tab.cpp | 4 ++-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/queue/action-queue-tab.cpp b/lib/queue/action-queue-tab.cpp index c04eff39..8282c07d 100644 --- a/lib/queue/action-queue-tab.cpp +++ b/lib/queue/action-queue-tab.cpp @@ -220,14 +220,15 @@ static void setupTab(QTabWidget *tab) } QWidget::connect(ActionQueueSignalManager::Instance(), - &ActionQueueSignalManager::Rename, + &ActionQueueSignalManager::Rename, tab, [](const QString &oldName, const QString &newName) { RenameItemTableRow(tabWidget->Table(), oldName, newName); }); QWidget::connect( ActionQueueSignalManager::Instance(), - &ActionQueueSignalManager::Add, [tab](const QString &name) { + &ActionQueueSignalManager::Add, tab, + [tab](const QString &name) { AddItemTableRow( tabWidget->Table(), getCellLabels(GetWeakActionQueueByQString(name) @@ -238,7 +239,7 @@ static void setupTab(QTabWidget *tab) setTabVisible(tab, true); }); QWidget::connect(ActionQueueSignalManager::Instance(), - &ActionQueueSignalManager::Remove, + &ActionQueueSignalManager::Remove, tab, [](const QString &name) { RemoveItemTableRow(tabWidget->Table(), name); if (tabWidget->Table()->rowCount() == 0) { diff --git a/lib/variables/variable-tab.cpp b/lib/variables/variable-tab.cpp index 98fb14c0..f6bea14d 100644 --- a/lib/variables/variable-tab.cpp +++ b/lib/variables/variable-tab.cpp @@ -273,14 +273,14 @@ static void setupTab(QTabWidget *tab) } QWidget::connect(VariableSignalManager::Instance(), - &VariableSignalManager::Rename, + &VariableSignalManager::Rename, tab, [](const QString &oldName, const QString &newName) { RenameItemTableRow(tabWidget->Table(), oldName, newName); }); QWidget::connect( VariableSignalManager::Instance(), &VariableSignalManager::Add, - [tab](const QString &name) { + tab, [tab](const QString &name) { AddItemTableRow( tabWidget->Table(), getCellLabels(GetVariableByQString(name))); @@ -289,7 +289,7 @@ static void setupTab(QTabWidget *tab) setTabVisible(tab, true); }); QWidget::connect(VariableSignalManager::Instance(), - &VariableSignalManager::Remove, + &VariableSignalManager::Remove, tab, [](const QString &name) { RemoveItemTableRow(tabWidget->Table(), name); if (tabWidget->Table()->rowCount() == 0) { diff --git a/plugins/base/utils/websocket-tab.cpp b/plugins/base/utils/websocket-tab.cpp index d5a52fda..1de6da51 100644 --- a/plugins/base/utils/websocket-tab.cpp +++ b/plugins/base/utils/websocket-tab.cpp @@ -207,14 +207,14 @@ static void setupTab(QTabWidget *tab) } QWidget::connect(ConnectionSelectionSignalManager::Instance(), - &ConnectionSelectionSignalManager::Rename, + &ConnectionSelectionSignalManager::Rename, tab, [](const QString &oldName, const QString &newName) { RenameItemTableRow(tabWidget->Table(), oldName, newName); }); QWidget::connect( ConnectionSelectionSignalManager::Instance(), - &ConnectionSelectionSignalManager::Add, + &ConnectionSelectionSignalManager::Add, tab, [tab](const QString &name) { AddItemTableRow( tabWidget->Table(), @@ -224,7 +224,7 @@ static void setupTab(QTabWidget *tab) setTabVisible(tab, true); }); QWidget::connect(ConnectionSelectionSignalManager::Instance(), - &ConnectionSelectionSignalManager::Remove, + &ConnectionSelectionSignalManager::Remove, tab, [](const QString &name) { RemoveItemTableRow(tabWidget->Table(), name); if (tabWidget->Table()->rowCount() == 0) { diff --git a/plugins/twitch/twitch-tab.cpp b/plugins/twitch/twitch-tab.cpp index 837aaf1e..3866c991 100644 --- a/plugins/twitch/twitch-tab.cpp +++ b/plugins/twitch/twitch-tab.cpp @@ -196,7 +196,7 @@ static void setupTab(QTabWidget *tab) QWidget::connect( TwitchConnectionSignalManager::Instance(), - &TwitchConnectionSignalManager::Add, + &TwitchConnectionSignalManager::Add, tab, [tab](const QString &name) { AddItemTableRow( tabWidget->Table(), @@ -208,7 +208,7 @@ static void setupTab(QTabWidget *tab) setTabVisible(tab, true); }); QWidget::connect(TwitchConnectionSignalManager::Instance(), - &TwitchConnectionSignalManager::Remove, + &TwitchConnectionSignalManager::Remove, tab, [](const QString &name) { RemoveItemTableRow(tabWidget->Table(), name); if (tabWidget->Table()->rowCount() == 0) {