From 94ac07cd73a315d7cc7d129f4ba4cf167848b859 Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 15 Mar 2021 11:44:34 +0000 Subject: [PATCH] Projucer: Fixed a potential crash in JucerTreeViewBase when dereferencing a deleted pointer to the underlying TreeViewItem --- .../Utility/UI/jucer_JucerTreeViewBase.cpp | 6 +----- .../Utility/UI/jucer_JucerTreeViewBase.h | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/extras/Projucer/Source/Utility/UI/jucer_JucerTreeViewBase.cpp b/extras/Projucer/Source/Utility/UI/jucer_JucerTreeViewBase.cpp index cfb3107477..6ed687fb71 100644 --- a/extras/Projucer/Source/Utility/UI/jucer_JucerTreeViewBase.cpp +++ b/extras/Projucer/Source/Utility/UI/jucer_JucerTreeViewBase.cpp @@ -61,16 +61,12 @@ void TreePanelBase::saveOpenness() } //============================================================================== -JucerTreeViewBase::JucerTreeViewBase() : textX (0) +JucerTreeViewBase::JucerTreeViewBase() { setLinesDrawnForSubItems (false); setDrawsInLeftMargin (true); } -JucerTreeViewBase::~JucerTreeViewBase() -{ -} - void JucerTreeViewBase::refreshSubItems() { WholeTreeOpennessRestorer wtor (*this); diff --git a/extras/Projucer/Source/Utility/UI/jucer_JucerTreeViewBase.h b/extras/Projucer/Source/Utility/UI/jucer_JucerTreeViewBase.h index f20c08c159..d560db2d8c 100644 --- a/extras/Projucer/Source/Utility/UI/jucer_JucerTreeViewBase.h +++ b/extras/Projucer/Source/Utility/UI/jucer_JucerTreeViewBase.h @@ -34,7 +34,7 @@ class JucerTreeViewBase : public TreeViewItem, { public: JucerTreeViewBase(); - ~JucerTreeViewBase() override; + ~JucerTreeViewBase() override = default; int getItemWidth() const override { return -1; } int getItemHeight() const override { return 25; } @@ -98,7 +98,7 @@ public: } }; - int textX; + int textX = 0; protected: ProjectContentComponent* getProjectContentComponent() const; @@ -203,21 +203,24 @@ private: class TreeItemComponent : public Component { public: - TreeItemComponent (JucerTreeViewBase& i) : item (i) + TreeItemComponent (JucerTreeViewBase& i) : item (&i) { setInterceptsMouseClicks (false, true); - item.textX = iconWidth; + item->textX = iconWidth; } void paint (Graphics& g) override { + if (item == nullptr) + return; + auto bounds = getLocalBounds().toFloat(); auto iconBounds = bounds.removeFromLeft ((float) iconWidth).reduced (7, 5); bounds.removeFromRight ((float) buttons.size() * bounds.getHeight()); - item.paintIcon (g, iconBounds); - item.paintContent (g, bounds.toNearestInt()); + item->paintIcon (g, iconBounds); + item->paintContent (g, bounds.toNearestInt()); } void resized() override @@ -225,7 +228,7 @@ public: auto r = getLocalBounds(); for (int i = buttons.size(); --i >= 0;) - buttons.getUnchecked(i)->setBounds (r.removeFromRight (r.getHeight())); + buttons.getUnchecked (i)->setBounds (r.removeFromRight (r.getHeight())); } void addRightHandButton (Component* button) @@ -234,7 +237,7 @@ public: addAndMakeVisible (button); } - JucerTreeViewBase& item; + WeakReference item; OwnedArray buttons; const int iconWidth = 25;