Skip to content

Commit 67b2153

Browse files
Merge #6609: backport: bitcoin-core/gui#693: Fix segfault when shutdown during wallet open
138e4fa Merge bitcoin-core/gui#693: Fix segfault when shutdown during wallet open (Hennadii Stepanov) Pull request description: ## Issue being fixed or feature implemented Pls see the original PR description + fixes dashpay/dash#6569 (comment) ## What was done? backport bitcoin-core/gui#693 ## How Has This Been Tested? Run `./src/qt/dash-qt` ## Breaking Changes n/a ## Checklist: - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [ ] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: PastaPastaPasta: utACK 138e4fa Tree-SHA512: 2ac5bf14f21626c5c5434f3f32d892d58d22da7a633558a0af2a56a1c63ef999d43a74c5c0fac8710ba1ad3927fd3021455707c715b72f6d25812d001463e17c
2 parents 873f1b3 + 138e4fa commit 67b2153

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/qt/bitcoingui.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,10 @@ void BitcoinGUI::setWalletController(WalletController* wallet_controller)
899899

900900
GUIUtil::ExceptionSafeConnect(wallet_controller, &WalletController::walletAdded, this, &BitcoinGUI::addWallet);
901901
connect(wallet_controller, &WalletController::walletRemoved, this, &BitcoinGUI::removeWallet);
902+
connect(wallet_controller, &WalletController::destroyed, this, [this] {
903+
// wallet_controller gets destroyed manually, but it leaves our member copy dangling
904+
m_wallet_controller = nullptr;
905+
});
902906

903907
auto activity = new LoadWalletsActivity(m_wallet_controller, this);
904908
activity->load();
@@ -911,7 +915,7 @@ WalletController* BitcoinGUI::getWalletController()
911915

912916
void BitcoinGUI::addWallet(WalletModel* walletModel)
913917
{
914-
if (!walletFrame) return;
918+
if (!walletFrame || !m_wallet_controller) return;
915919

916920
WalletView* wallet_view = new WalletView(walletModel, walletFrame);
917921
if (!walletFrame->addView(wallet_view)) return;
@@ -959,7 +963,7 @@ void BitcoinGUI::removeWallet(WalletModel* walletModel)
959963

960964
void BitcoinGUI::setCurrentWallet(WalletModel* wallet_model)
961965
{
962-
if (!walletFrame) return;
966+
if (!walletFrame || !m_wallet_controller) return;
963967
walletFrame->setCurrentWallet(wallet_model);
964968
for (int index = 0; index < m_wallet_selector->count(); ++index) {
965969
if (m_wallet_selector->itemData(index).value<WalletModel*>() == wallet_model) {

src/qt/sendcoinsdialog.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -604,10 +604,15 @@ SendCoinsEntry *SendCoinsDialog::addEntry()
604604
entry->clear();
605605
entry->setFocus();
606606
ui->scrollAreaWidgetContents->resize(ui->scrollAreaWidgetContents->sizeHint());
607-
qApp->processEvents();
608-
QScrollBar* bar = ui->scrollArea->verticalScrollBar();
609-
if(bar)
610-
bar->setSliderPosition(bar->maximum());
607+
608+
// Scroll to the newly added entry on a QueuedConnection because Qt doesn't
609+
// adjust the scroll area and scrollbar immediately when the widget is added.
610+
// Invoking on a DirectConnection will only scroll to the second-to-last entry.
611+
QMetaObject::invokeMethod(ui->scrollArea, [this] {
612+
if (ui->scrollArea->verticalScrollBar()) {
613+
ui->scrollArea->verticalScrollBar()->setValue(ui->scrollArea->verticalScrollBar()->maximum());
614+
}
615+
}, Qt::QueuedConnection);
611616

612617
updateTabsAndLabels();
613618
return entry;

src/qt/test/wallettests.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ void TestGUI(interfaces::Node& node)
163163
QCOMPARE(transactionTableModel->rowCount({}), 105);
164164
uint256 txid1 = SendCoins(*wallet.get(), sendCoinsDialog, PKHash(), 5 * COIN);
165165
uint256 txid2 = SendCoins(*wallet.get(), sendCoinsDialog, PKHash(), 10 * COIN);
166+
// Transaction table model updates on a QueuedConnection, so process events to ensure it's updated.
167+
qApp->processEvents();
166168
QCOMPARE(transactionTableModel->rowCount({}), 107);
167169
QVERIFY(FindTx(*transactionTableModel, txid1).isValid());
168170
QVERIFY(FindTx(*transactionTableModel, txid2).isValid());

0 commit comments

Comments
 (0)