diff --git a/Telegram/SourceFiles/dialogs/dialogs_indexed_list.cpp b/Telegram/SourceFiles/dialogs/dialogs_indexed_list.cpp index 5d6b25748..e7a8ee694 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_indexed_list.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_indexed_list.cpp @@ -91,6 +91,19 @@ void IndexedList::movePinned(Row *row, int deltaSign) { } auto history1 = row->history(); auto history2 = (*swapPinnedIndexWith)->history(); + + // Debug an assertion violation. + if (!history2->isPinnedDialog()) { + auto myPinnedCount = 0; + for_const (auto row, *this) { + if (!row->history()->isPinnedDialog()) { + break; + } + ++myPinnedCount; + } + SignalHandlers::setCrashAnnotation("DebugInfo", QString("row index: %1, deltaSign: %2, pinnedCount: %3, myPinnedCount: %4").arg(row->pos()).arg(deltaSign).arg(App::histories().pinnedCount()).arg(myPinnedCount)); + } + t_assert(history1->isPinnedDialog()); t_assert(history2->isPinnedDialog()); auto index1 = history1->getPinnedIndex(); diff --git a/Telegram/SourceFiles/dialogswidget.cpp b/Telegram/SourceFiles/dialogswidget.cpp index 144a3ed42..4f7c5b97a 100644 --- a/Telegram/SourceFiles/dialogswidget.cpp +++ b/Telegram/SourceFiles/dialogswidget.cpp @@ -721,6 +721,20 @@ bool DialogsInner::updateReorderPinned(QPoint localPosition) { auto rowHeight = st::dialogsRowHeight; if (_dragStart.y() > localPosition.y() && _draggingIndex > 0) { shift = -floorclamp(_dragStart.y() - localPosition.y() + (rowHeight / 2), rowHeight, 0, _draggingIndex); + + // Debug an assertion violation. + if (shift < 0) { + auto index = 0; + for_const (auto row, *shownDialogs()) { + if (++index >= _draggingIndex + shift) { + t_assert(row->history()->isPinnedDialog()); + if (index >= _draggingIndex) { + break; + } + } + } + } + for (auto from = _draggingIndex, to = _draggingIndex + shift; from > to; --from) { shownDialogs()->movePinned(_dragging, -1); std::swap(_pinnedRows[from], _pinnedRows[from - 1]); @@ -729,6 +743,20 @@ bool DialogsInner::updateReorderPinned(QPoint localPosition) { } } else if (_dragStart.y() < localPosition.y() && _draggingIndex + 1 < pinnedCount) { shift = floorclamp(localPosition.y() - _dragStart.y() + (rowHeight / 2), rowHeight, 0, pinnedCount - _draggingIndex - 1); + + // Debug an assertion violation. + if (shift > 0) { + auto index = 0; + for_const (auto row, *shownDialogs()) { + if (++index >= _draggingIndex) { + t_assert(row->history()->isPinnedDialog()); + if (index >= _draggingIndex + shift) { + break; + } + } + } + } + for (auto from = _draggingIndex, to = _draggingIndex + shift; from < to; ++from) { shownDialogs()->movePinned(_dragging, 1); std::swap(_pinnedRows[from], _pinnedRows[from + 1]);