From e4b8c9eac20dc867ad8a1c44bc6ca3460ac5aa93 Mon Sep 17 00:00:00 2001 From: Deve Date: Fri, 19 Oct 2018 22:44:53 +0200 Subject: [PATCH] Avoid a crash in friends list. Not my fault, but indeed it was crashing when you enabled sorting and then opened friends list in your friend profile. --- .../online/online_profile_friends.cpp | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/states_screens/online/online_profile_friends.cpp b/src/states_screens/online/online_profile_friends.cpp index b72bd655c..bf3ec7eaa 100644 --- a/src/states_screens/online/online_profile_friends.cpp +++ b/src/states_screens/online/online_profile_friends.cpp @@ -195,9 +195,18 @@ bool OnlineProfileFriends::compareFriends(int f1, int f2) void OnlineProfileFriends::displayResults() { m_friends_list_widget->clear(); + OnlineProfile::IDList friends = m_visiting_profile->getFriends(); - (m_sort_desc && !m_sort_default) ? std::sort(friends.rbegin(), friends.rend(), compareFriends) - : std::sort(friends.begin(), friends.end(), compareFriends); + + if (m_sort_desc && !m_sort_default) + { + std::sort(friends.rbegin(), friends.rend(), compareFriends); + } + else + { + std::sort(friends.begin(), friends.end(), compareFriends); + } + for (unsigned int i = 0; i < friends.size(); i++) { std::vector row; @@ -245,8 +254,17 @@ void OnlineProfileFriends::onUpdate(float delta) { if(m_waiting_for_friends) { - if(m_visiting_profile->hasFetchedFriends()) + if (m_visiting_profile->hasFetchedFriends()) { + // When browsing other users friends there is no Since/Status + // columns, so force sorting by name + if (!m_visiting_profile->isCurrentUser() && m_sort_column != 0) + { + m_sort_column = 0; + m_sort_desc = false; + m_sort_default = true; + } + displayResults(); } else