0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 13:08:50 +02:00
Commit Graph

3 Commits

Author SHA1 Message Date
Palana
3fc7453933 UI: Clear ListItem selection before deleting widgets
This works around a crash in the "widget->clear()" call in
ClearListItems under the following circumstances:
- Create at least two scenes
- Create at least one source in both scenes
- Have at least one source selected in both scenes
- Set the same "Switch to scene" hotkey on both scenes
- Use "Switch to scene" hotkey

Reduced stack trace on my machine:
    frame #0: 0x00000001004bac2d QtWidgets`QWidget::show() + 93
    frame #1: 0x00000001006d32a2 QtWidgets`QAbstractItemView::updateEditorGeometries() + 690
    frame #2: 0x00000001006d36d7 QtWidgets`QAbstractItemView::updateGeometries() + 23
    frame #3: 0x00000001006f1ae6 QtWidgets`QListView::updateGeometries() + 438
    frame #4: 0x00000001006ccdce QtWidgets`QAbstractItemView::doItemsLayout() + 46
    frame #5: 0x00000001006f1916 QtWidgets`QListView::doItemsLayout() + 214
    frame #6: 0x00000001006f9cf3 QtWidgets`QListViewPrivate::rectForIndex(QModelIndex const&) const + 611
    frame #7: 0x00000001006eb48d QtWidgets`QListView::visualRect(QModelIndex const&) const + 29
    frame #8: 0x00000001006f1567 QtWidgets`QListView::visualRegionForSelection(QItemSelection const&) const + 1863
    frame #9: 0x00000001006d7ba9 QtWidgets`QAbstractItemView::selectionChanged(QItemSelection const&, QItemSelection const&) + 73
    frame #10: 0x00000001006f97d2 QtWidgets`QListView::selectionChanged(QItemSelection const&, QItemSelection const&) + 674
    frame #11: 0x00000001006d9b9e QtWidgets`QAbstractItemView::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) + 1246
    frame #12: 0x0000000102b10372 QtCore`QMetaObject::activate(QObject*, int, int, void**) + 2994
    frame #13: 0x0000000102aa001c QtCore`QItemSelectionModel::emitSelectionChanged(QItemSelection const&, QItemSelection const&) + 300
    frame #14: 0x0000000102a9fe6c QtCore`QItemSelectionModel::select(QItemSelection const&, QFlags<QItemSelectionModel::SelectionFlag>) + 748
    frame #15: 0x0000000102aa048b QtCore`QItemSelectionModel::clear() + 75
    frame #16: 0x000000010072e9d8 QtWidgets`QListWidget::clear() + 24
    frame #17: 0x000000010015759d obs`ClearListItems(widget=0x000000010683afa0) + 141 at item-widget-helpers.cpp:43
    frame #18: 0x000000010003424b obs`OBSBasic::UpdateSources(this=0x0000000105f5bf50, scene=(val = obs_scene * = 0x0000000110679440)), &(obs_scene_release)>) + 75 at window-basic-main.cpp:1254
    frame #19: 0x0000000100036a96 obs`OBSBasic::UpdateSceneSelection(this=0x0000000105f5bf50, source=<unavailable>), &(obs_source_release)>) + 422 at window-basic-main.cpp:1473
    frame #20: 0x0000000100175c48 obs`OBSBasic::qt_static_metacall(_o=0x0000000105f5bf50, _c=InvokeMetaMethod, _id=17, _a=0x00007fff5fbfb640) + 776 at moc_window-basic-main.cpp:494

This crash was reported at
https://obsproject.com/mantis/view.php?id=364
2015-11-06 11:36:51 +01:00
jp9000
815b916b73 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.
2015-07-02 22:07:39 -07:00
jp9000
db9e966e6c UI: Add item widget helper functions
These functions are designed to manually delete item widgets within
other widgets to prevent ->deleteLater from being called on them.  This
prevents the item widgets from being stuck in the event queue, and
prevents references to things like sources from being stuck in the event
queue along with them if they're used in the item widget's class or
functions.
2015-07-02 17:56:03 -07:00