From acefc92f88ea68117c150d9e1490afa378503ebc Mon Sep 17 00:00:00 2001 From: reuk Date: Fri, 13 May 2022 09:44:33 +0100 Subject: [PATCH] TableListBox: Avoid calling virtual functions in constructor --- modules/juce_gui_basics/widgets/juce_ListBox.cpp | 16 ++++++++++------ modules/juce_gui_basics/widgets/juce_ListBox.h | 1 + .../widgets/juce_TableListBox.cpp | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/modules/juce_gui_basics/widgets/juce_ListBox.cpp b/modules/juce_gui_basics/widgets/juce_ListBox.cpp index 7f3bd24533..a5fb38ac94 100644 --- a/modules/juce_gui_basics/widgets/juce_ListBox.cpp +++ b/modules/juce_gui_basics/widgets/juce_ListBox.cpp @@ -537,16 +537,20 @@ ListBox::~ListBox() viewport.reset(); } +void ListBox::assignModelPtr (ListBoxModel* const newModel) +{ + model = newModel; + + #if ! JUCE_DISABLE_ASSERTIONS + weakModelPtr = model != nullptr ? model->sharedState : nullptr; + #endif +} + void ListBox::setModel (ListBoxModel* const newModel) { if (model != newModel) { - model = newModel; - - #if ! JUCE_DISABLE_ASSERTIONS - weakModelPtr = model != nullptr ? model->sharedState : nullptr; - #endif - + assignModelPtr (newModel); repaint(); updateContent(); } diff --git a/modules/juce_gui_basics/widgets/juce_ListBox.h b/modules/juce_gui_basics/widgets/juce_ListBox.h index c6488fb309..bcdfc17a33 100644 --- a/modules/juce_gui_basics/widgets/juce_ListBox.h +++ b/modules/juce_gui_basics/widgets/juce_ListBox.h @@ -613,6 +613,7 @@ private: std::weak_ptr weakModelPtr; #endif + void assignModelPtr (ListBoxModel*); void checkModelPtrIsValid() const; std::unique_ptr createAccessibilityHandler() override; bool hasAccessibleHeaderComponent() const; diff --git a/modules/juce_gui_basics/widgets/juce_TableListBox.cpp b/modules/juce_gui_basics/widgets/juce_TableListBox.cpp index 84e9a6bbf5..2f8828a2cf 100644 --- a/modules/juce_gui_basics/widgets/juce_TableListBox.cpp +++ b/modules/juce_gui_basics/widgets/juce_TableListBox.cpp @@ -339,7 +339,7 @@ private: TableListBox::TableListBox (const String& name, TableListBoxModel* const m) : ListBox (name, nullptr), model (m) { - ListBox::setModel (this); + ListBox::assignModelPtr (this); setHeader (std::make_unique
(*this)); }