Fix async result handlers

PR #22669.
Closes #22644.
This commit is contained in:
Vladimir Golovnev 2025-05-10 10:17:35 +03:00 committed by GitHub
commit dcaf4b6d80
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 21 additions and 19 deletions

View file

@ -409,8 +409,11 @@ void PeerListWidget::loadPeers(const BitTorrent::Torrent *torrent)
using TorrentPtr = QPointer<const BitTorrent::Torrent>;
torrent->fetchPeerInfo().then(this, [this, torrent = TorrentPtr(torrent)](const QList<BitTorrent::PeerInfo> &peers)
{
if (torrent != m_properties->getCurrentTorrent())
if (const BitTorrent::Torrent *currentTorrent = m_properties->getCurrentTorrent();
!currentTorrent || (currentTorrent != torrent))
{
return;
}
// Remove I2P peers since they will be completely reloaded.
for (const QStandardItem *item : asConst(m_I2PPeerItems))

View file

@ -480,9 +480,10 @@ void PropertiesWidget::loadDynamicData()
showPiecesAvailability(true);
using TorrentPtr = QPointer<BitTorrent::Torrent>;
m_torrent->fetchPieceAvailability().then(this, [this, torrent = TorrentPtr(m_torrent)](const QList<int> &pieceAvailability)
m_torrent->fetchPieceAvailability().then(this
, [this, torrent = TorrentPtr(m_torrent)](const QList<int> &pieceAvailability)
{
if (torrent == m_torrent)
if (m_torrent && (m_torrent == torrent))
m_piecesAvailability->setAvailability(pieceAvailability);
});
@ -497,9 +498,12 @@ void PropertiesWidget::loadDynamicData()
qreal progress = m_torrent->progress() * 100.;
m_ui->labelProgressVal->setText(Utils::String::fromDouble(progress, 1) + u'%');
m_torrent->fetchDownloadingPieces().then(this, [this](const QBitArray &downloadingPieces)
using TorrentPtr = QPointer<BitTorrent::Torrent>;
m_torrent->fetchDownloadingPieces().then(this
, [this, torrent = TorrentPtr(m_torrent)](const QBitArray &downloadingPieces)
{
m_downloadedPieces->setProgress(m_torrent->pieces(), downloadingPieces);
if (m_torrent && (m_torrent == torrent))
m_downloadedPieces->setProgress(m_torrent->pieces(), downloadingPieces);
});
}
else
@ -527,7 +531,7 @@ void PropertiesWidget::loadUrlSeeds()
using TorrentPtr = QPointer<BitTorrent::Torrent>;
m_torrent->fetchURLSeeds().then(this, [this, torrent = TorrentPtr(m_torrent)](const QList<QUrl> &urlSeeds)
{
if (torrent != m_torrent)
if (!m_torrent || (m_torrent != torrent))
return;
m_ui->listWebSeeds->clear();

View file

@ -223,16 +223,11 @@ void TorrentContentModel::updateFilesAvailability()
m_contentHandler->fetchAvailableFileFractions().then(this
, [this, handler = HandlerPtr(m_contentHandler)](const QList<qreal> &availableFileFractions)
{
if (handler != m_contentHandler)
return;
Q_ASSERT(m_filesIndex.size() == availableFileFractions.size());
// XXX: Why is this necessary?
if (m_filesIndex.size() != availableFileFractions.size()) [[unlikely]]
if (!m_contentHandler || (m_contentHandler != handler))
return;
for (int i = 0; i < m_filesIndex.size(); ++i)
m_filesIndex[i]->setAvailability(availableFileFractions[i]);
m_filesIndex[i]->setAvailability(availableFileFractions.value(i, 0));
// Update folders progress in the tree
m_rootItem->recalculateProgress();
});

View file

@ -312,14 +312,14 @@ void TrackerListModel::populate()
using TorrentPtr = QPointer<const BitTorrent::Torrent>;
m_torrent->fetchPeerInfo().then(this, [this, torrent = TorrentPtr(m_torrent)](const QList<BitTorrent::PeerInfo> &peers)
{
if (torrent != m_torrent)
if (!m_torrent || (m_torrent != torrent))
return;
// XXX: libtorrent should provide this info...
// Count peers from DHT, PeX, LSD
uint seedsDHT = 0, seedsPeX = 0, seedsLSD = 0, peersDHT = 0, peersPeX = 0, peersLSD = 0;
for (const BitTorrent::PeerInfo &peer : peers)
{
// XXX: libtorrent should provide this info...
// Count peers from DHT, PeX, LSD
uint seedsDHT = 0, seedsPeX = 0, seedsLSD = 0, peersDHT = 0, peersPeX = 0, peersLSD = 0;
for (const BitTorrent::PeerInfo &peer : peers)
{
if (peer.isConnecting())
continue;