Skip to content

Commit

Permalink
Add comments about the risk of dangling pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer committed Feb 3, 2023
1 parent d71b91e commit 4834e90
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/library/baseexternallibraryfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ void BaseExternalLibraryFeature::onRightClick(const QPoint& globalPos) {

void BaseExternalLibraryFeature::onRightClickChild(
const QPoint& globalPos, const QModelIndex& index) {
//Save the model index so we can get it in the action slots...
// Save the model index so we can get it in the action slots...
// Make sure that this is reset when the related TreeItem is deleted.
m_lastRightClickedIndex = index;
QMenu menu(m_pSidebarWidget);
menu.addAction(m_pAddToAutoDJAction);
Expand Down
2 changes: 2 additions & 0 deletions src/library/baseexternallibraryfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class BaseExternalLibraryFeature : public LibraryFeature {
private:
void addToAutoDJ(PlaylistDAO::AutoDJSendLoc loc);

// Caution: Make sure this is reset whenever the library tree is updated,
// so that the internalPointer() does not become dangling
QModelIndex m_lastRightClickedIndex;

parented_ptr<QAction> m_pAddToAutoDJAction;
Expand Down
2 changes: 2 additions & 0 deletions src/library/browse/browsefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ void BrowseFeature::activateChild(const QModelIndex& index) {

void BrowseFeature::onRightClickChild(const QPoint& globalPos, const QModelIndex& index) {
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());

// Make sure that this is reset when the related TreeItem is deleted.
m_pLastRightClickedItem = item;

if (!item) {
Expand Down
3 changes: 3 additions & 0 deletions src/library/browse/browsefeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class BrowseFeature : public LibraryFeature {
QAction* m_pAddQuickLinkAction;
QAction* m_pRemoveQuickLinkAction;
QAction* m_pAddtoLibraryAction;

// Caution: Make sure this is reset whenever the library tree is updated,
// so that the internalPointer() does not become dangling
TreeItem* m_pLastRightClickedItem;
TreeItem* m_pQuickLinkItem;
QStringList m_quickLinkList;
Expand Down

0 comments on commit 4834e90

Please sign in to comment.