[vlc-commits] [Git][videolan/vlc][master] qt: fix deleting/updating items in cache before it's loaded
    Jean-Baptiste Kempf (@jbk) 
    gitlab at videolan.org
       
    Mon Apr  4 17:22:23 UTC 2022
    
    
  
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
572b5887 by Pierre Lamot at 2022-04-04T17:01:17+00:00
qt: fix deleting/updating items in cache before it's loaded
- - - - -
1 changed file:
- modules/gui/qt/medialibrary/mllistcache.cpp
Changes:
=====================================
modules/gui/qt/medialibrary/mllistcache.cpp
=====================================
@@ -143,6 +143,10 @@ int MLListCache::updateItem(std::unique_ptr<MLItem>&& newItem)
     if (m_oldData)
         return -1;
 
+    //we can't update an item before we have any cache
+    if (unlikely(!m_cachedData))
+        return -1;
+
     MLItemId mlid = newItem->getId();
     //this may be inneficient to look at every items, maybe we can have a hashmap to access the items by id
     auto it = std::find_if(m_cachedData->list.begin(), m_cachedData->list.end(), [mlid](const ItemType& item) {
@@ -165,6 +169,10 @@ int MLListCache::deleteItem(const MLItemId& mlid)
     if (m_oldData)
         return -1;
 
+    //we can't remove an item before we have any cache
+    if (unlikely(!m_cachedData))
+        return -1;
+
     auto it = std::find_if(m_cachedData->list.begin(), m_cachedData->list.end(), [mlid](const ItemType& item) {
         return (item->getId() == mlid);
     });
@@ -192,6 +200,9 @@ void MLListCache::moveRange(int first, int last, int to)
     if (first <= to && to <= last)
         return;
 
+    if (unlikely(!m_cachedData))
+        return;
+
     emit beginMoveRows(first, last, to);
     auto it = m_cachedData->list.begin();
     //build a temporary list with the items in order
@@ -217,6 +228,9 @@ void MLListCache::moveRange(int first, int last, int to)
 
 void MLListCache::deleteRange(int first, int last)
 {
+    if (unlikely(!m_cachedData))
+        return;
+
     assert(first <= last);
     emit beginRemoveRows(first, last);
     auto it = m_cachedData->list.begin();
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/572b5887c4c8d523788348e96111cc225110cc40
-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/572b5887c4c8d523788348e96111cc225110cc40
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
    
    
More information about the vlc-commits
mailing list