From 815b916b736522b78998468afe3405ef184ff197 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Thu, 2 Jul 2015 21:56:30 -0700 Subject: [PATCH] UI: Do not delete via takeItem in ClearListItems Apparently some raw lingering pointers to the item widgets may be present inside of the QListView if you delete the item widgets directly, and the only way to ensure those pointers are properly cleared is to call ->clear() on the list widget instead of deleting each item individually. We were deleting each item individually because we thought that ->deleteLater might be also be called on other data within, but after some testing, that turned out to not be the case, so it's safe to call ->clear() on the list widget. As a note, deleting item widgets directly is dangerous due to the potential for lingering raw internal pointers, and our case is unique where we can get away with it; do not delete list item widgets directly unless you intend on calling ->clear() or ->takeItem on the specific item you do it to after. Again, the reason why we are deleting list widget items manually is due to the fact that Qt will always use ->deleteLater() on them if they are not deleted manually, which puts their deletion on the queue. Only problem is they cannot be removed from the queue once added, so lingering references to sources will persist until the queue processes them, which causes major problems if we need those objects deleted right away. --- obs/item-widget-helpers.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/obs/item-widget-helpers.cpp b/obs/item-widget-helpers.cpp index 9139ccb40..c8eae6f78 100644 --- a/obs/item-widget-helpers.cpp +++ b/obs/item-widget-helpers.cpp @@ -40,7 +40,5 @@ void ClearListItems(QListWidget *widget) for (int i = 0; i < widget->count(); i++) delete widget->itemWidget(widget->item(i)); - QListWidgetItem *item = nullptr; - while ((item = widget->takeItem(0))) - delete item; + widget->clear(); }