Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Projucer: Fixed a potential crash in JucerTreeViewBase when dereferen…
…cing a deleted pointer to the underlying TreeViewItem
  • Loading branch information
ed95 committed Apr 27, 2021
1 parent d6ac6b5 commit 94ac07c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
Expand Up @@ -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);
Expand Down
19 changes: 11 additions & 8 deletions extras/Projucer/Source/Utility/UI/jucer_JucerTreeViewBase.h
Expand Up @@ -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; }
Expand Down Expand Up @@ -98,7 +98,7 @@ class JucerTreeViewBase : public TreeViewItem,
}
};

int textX;
int textX = 0;

protected:
ProjectContentComponent* getProjectContentComponent() const;
Expand Down Expand Up @@ -203,29 +203,32 @@ class TreePanelBase : public Component
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
{
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)
Expand All @@ -234,7 +237,7 @@ class TreeItemComponent : public Component
addAndMakeVisible (button);
}

JucerTreeViewBase& item;
WeakReference<JucerTreeViewBase> item;
OwnedArray<Component> buttons;

const int iconWidth = 25;
Expand Down

0 comments on commit 94ac07c

Please sign in to comment.