fix: assert failure when moving torrents to bottom of the queue (#6751)

This commit is contained in:
Yat Ho 2024-03-31 02:49:03 +08:00 committed by GitHub
parent bc7d447949
commit 8944e587f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 6 deletions

View File

@ -498,15 +498,18 @@ void tr_torrent::set_unique_queue_position(size_t const new_pos)
{ {
using namespace queue_helpers; using namespace queue_helpers;
auto current = size_t{}; auto max_pos = size_t{};
auto const old_pos = queue_position_; auto const old_pos = queue_position_;
queue_position_ = MaxQueuePosition;
auto& torrents = session->torrents(); auto& torrents = session->torrents();
for (auto* const walk : torrents) for (auto* const walk : torrents)
{ {
if ((old_pos < new_pos) && (old_pos <= walk->queue_position_) && (walk->queue_position_ <= new_pos)) if (walk == this)
{
continue;
}
if ((old_pos < new_pos) && (old_pos < walk->queue_position_) && (walk->queue_position_ <= new_pos))
{ {
--walk->queue_position_; --walk->queue_position_;
walk->mark_changed(); walk->mark_changed();
@ -518,10 +521,10 @@ void tr_torrent::set_unique_queue_position(size_t const new_pos)
walk->mark_changed(); walk->mark_changed();
} }
current = std::max(current, walk->queue_position_ + 1U); max_pos = std::max(max_pos, walk->queue_position_);
} }
queue_position_ = std::min(new_pos, current); queue_position_ = std::min(new_pos, max_pos + 1);
mark_changed(); mark_changed();
TR_ASSERT(torrents_are_sorted_by_queue_position(torrents.get_all())); TR_ASSERT(torrents_are_sorted_by_queue_position(torrents.get_all()));