Browse Source

Added the JUCE_DECLARE_WEAK_REFERENCEABLE macro to ValueWithDefault and fixed some places which were potentially accessing a deleted ValueWithDefault object

tags/2021-05-28
ed 7 years ago
parent
commit
35890478a3
7 changed files with 38 additions and 11 deletions
  1. +13
    -1
      modules/juce_data_structures/values/juce_ValueWithDefault.h
  2. +7
    -1
      modules/juce_gui_basics/properties/juce_ChoicePropertyComponent.cpp
  3. +1
    -2
      modules/juce_gui_basics/properties/juce_ChoicePropertyComponent.h
  4. +7
    -1
      modules/juce_gui_basics/properties/juce_MultiChoicePropertyComponent.cpp
  5. +1
    -2
      modules/juce_gui_basics/properties/juce_MultiChoicePropertyComponent.h
  6. +8
    -2
      modules/juce_gui_basics/properties/juce_TextPropertyComponent.cpp
  7. +1
    -2
      modules/juce_gui_basics/properties/juce_TextPropertyComponent.h

+ 13
- 1
modules/juce_data_structures/values/juce_ValueWithDefault.h View File

@@ -181,6 +181,15 @@ public:
/** Returns the property ID of the referenced property. */
Identifier& getPropertyID() noexcept { return targetProperty; }
//==============================================================================
ValueWithDefault& operator= (const ValueWithDefault& other)
{
referToWithDefault (other.targetTree, other.targetProperty, other.undoManager,
other.defaultValue, other.delimiter);
return *this;
}
private:
//==============================================================================
ValueTree targetTree;
@@ -191,7 +200,7 @@ private:
String delimiter;
//==============================================================================
void referToWithDefault (ValueTree& v, const Identifier& i, UndoManager* um,
void referToWithDefault (const ValueTree& v, const Identifier& i, UndoManager* um,
const var& defaultVal, StringRef del)
{
targetTree = v;
@@ -225,6 +234,9 @@ private:
return arr;
}
//==============================================================================
JUCE_DECLARE_WEAK_REFERENCEABLE (ValueWithDefault)
};
} // namespace juce

+ 7
- 1
modules/juce_gui_basics/properties/juce_ChoicePropertyComponent.cpp View File

@@ -83,6 +83,9 @@ public:
var getValue() const override
{
if (valueWithDefault == nullptr)
return {};
if (valueWithDefault->isUsingDefault())
return -1;
@@ -97,6 +100,9 @@ public:
void setValue (const var& newValue) override
{
if (valueWithDefault == nullptr)
return;
auto newValueInt = static_cast<int> (newValue);
if (newValueInt == -1)
@@ -115,7 +121,7 @@ public:
private:
void valueChanged (Value&) override { sendChangeMessage (true); }
ValueWithDefault* valueWithDefault = nullptr;
WeakReference<ValueWithDefault> valueWithDefault;
Value sourceValue;
Array<var> mappings;


+ 1
- 2
modules/juce_gui_basics/properties/juce_ChoicePropertyComponent.h View File

@@ -84,7 +84,6 @@ public:
default value with an ID of -1.
@param valueToControl the ValueWithDefault object that contains the Value object that the combo box will read and control.
NB: this object must outlive the ChoicePropertyComponent.
@param propertyName the name of the property
@param choices the list of possible values that the drop-down list will contain
@param correspondingValues a list of values corresponding to each item in the 'choices' StringArray.
@@ -154,7 +153,7 @@ private:
ComboBox comboBox;
bool isCustomClass = false;
ValueWithDefault* valueWithDefault = nullptr;
WeakReference<ValueWithDefault> valueWithDefault;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChoicePropertyComponent)


+ 7
- 1
modules/juce_gui_basics/properties/juce_MultiChoicePropertyComponent.cpp View File

@@ -118,6 +118,9 @@ public:
var getValue() const override
{
if (valueWithDefault == nullptr)
return {};
auto v = valueWithDefault->get();
if (auto* arr = v.getArray())
@@ -134,6 +137,9 @@ public:
void setValue (const var& newValue) override
{
if (valueWithDefault == nullptr)
return;
auto v = valueWithDefault->get();
OptionalScopedPointer<Array<var>> arrayToControl;
@@ -191,7 +197,7 @@ private:
}
//==============================================================================
ValueWithDefault* valueWithDefault = nullptr;
WeakReference<ValueWithDefault> valueWithDefault;
var varToControl;
Value sourceValue;


+ 1
- 2
modules/juce_gui_basics/properties/juce_MultiChoicePropertyComponent.h View File

@@ -67,7 +67,6 @@ public:
/** Creates the component using a ValueWithDefault object. This will select the default options.
@param valueToControl the ValueWithDefault object that contains the Value object that the ToggleButtons will read and control.
NB: This object must outlive the MultiChoicePropertyComponent.
@param propertyName the name of the property
@param choices the list of possible values that will be represented
@param correspondingValues a list of values corresponding to each item in the 'choices' StringArray.
@@ -119,7 +118,7 @@ private:
void lookAndFeelChanged() override;
//==============================================================================
ValueWithDefault* valueWithDefault = nullptr;
WeakReference<ValueWithDefault> valueWithDefault;
int maxHeight = 0;
int numHidden = 0;


+ 8
- 2
modules/juce_gui_basics/properties/juce_TextPropertyComponent.cpp View File

@@ -131,11 +131,17 @@ public:
var getValue() const override
{
return valueWithDefault->isUsingDefault() ? var() : valueWithDefault->get();
if (valueWithDefault == nullptr || valueWithDefault->isUsingDefault())
return {};
return valueWithDefault->get();
}
void setValue (const var& newValue) override
{
if (valueWithDefault == nullptr)
return;
if (newValue.toString().isEmpty())
valueWithDefault->resetToDefault();
else
@@ -143,7 +149,7 @@ public:
}
private:
ValueWithDefault* valueWithDefault = nullptr;
WeakReference<ValueWithDefault> valueWithDefault;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (RemapperValueSourceWithDefault)


+ 1
- 2
modules/juce_gui_basics/properties/juce_TextPropertyComponent.h View File

@@ -75,7 +75,6 @@ public:
/** Creates a text property component with a default value.
@param valueToControl The ValueWithDefault that is controlled by the TextPropertyComponent.
NB: this object must outlive the TextPropertyComponent.
@param propertyName The name of the property
@param maxNumChars If not zero, then this specifies the maximum allowable length of
the string. If zero, then the string will have no length limit.
@@ -183,7 +182,7 @@ private:
std::unique_ptr<LabelComp> textEditor;
ListenerList<Listener> listenerList;
ValueWithDefault* valueWithDefault = nullptr;
WeakReference<ValueWithDefault> valueWithDefault;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TextPropertyComponent)


Loading…
Cancel
Save