| @@ -248,7 +248,7 @@ void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup) cons | |||||
| XmlElement* AudioDeviceManager::createStateXml() const | XmlElement* AudioDeviceManager::createStateXml() const | ||||
| { | { | ||||
| return lastExplicitSettings != nullptr ? new XmlElement (*lastExplicitSettings) : nullptr; | |||||
| return lastExplicitSettings.createCopy(); | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -75,6 +75,11 @@ inline Type* addBytesToPointer (Type* pointer, int bytes) noexcept { return (Ty | |||||
| template <typename Type1, typename Type2> | template <typename Type1, typename Type2> | ||||
| inline int getAddressDifference (Type1* pointer1, Type2* pointer2) noexcept { return (int) (((const char*) pointer1) - (const char*) pointer2); } | inline int getAddressDifference (Type1* pointer1, Type2* pointer2) noexcept { return (int) (((const char*) pointer1) - (const char*) pointer2); } | ||||
| /** If a pointer is non-null, this returns a new copy of the object that it points to, or safely returns | |||||
| nullptr if the pointer is null. | |||||
| */ | |||||
| template <class Type> | |||||
| inline Type* createCopyIfNotNull (Type* pointer) { return pointer != nullptr ? new Type (*pointer) : nullptr; } | |||||
| //============================================================================== | //============================================================================== | ||||
| /* In a Windows DLL build, we'll expose some malloc/free functions that live inside the DLL, and use these for | /* In a Windows DLL build, we'll expose some malloc/free functions that live inside the DLL, and use these for | ||||
| @@ -169,6 +169,11 @@ public: | |||||
| std::swap (object, other.object); | std::swap (object, other.object); | ||||
| } | } | ||||
| /** If the pointer is non-null, this will attempt to return a new copy of the object that is pointed to. | |||||
| If the pointer is null, this will safely return a nullptr. | |||||
| */ | |||||
| inline ObjectType* createCopy() const { return createCopyIfNotNull (object); } | |||||
| private: | private: | ||||
| //============================================================================== | //============================================================================== | ||||
| ObjectType* object; | ObjectType* object; | ||||
| @@ -708,7 +708,7 @@ bool ValueTree::isEquivalentTo (const ValueTree& other) const | |||||
| ValueTree ValueTree::createCopy() const | ValueTree ValueTree::createCopy() const | ||||
| { | { | ||||
| return ValueTree (object != nullptr ? new SharedObject (*object) : nullptr); | |||||
| return ValueTree (createCopyIfNotNull (object.getObject())); | |||||
| } | } | ||||
| bool ValueTree::hasType (const Identifier& typeName) const | bool ValueTree::hasType (const Identifier& typeName) const | ||||
| @@ -48,7 +48,7 @@ FillType::FillType (const Image& image_, const AffineTransform& transform_) noex | |||||
| FillType::FillType (const FillType& other) | FillType::FillType (const FillType& other) | ||||
| : colour (other.colour), | : colour (other.colour), | ||||
| gradient (other.gradient != nullptr ? new ColourGradient (*other.gradient) : nullptr), | |||||
| gradient (other.gradient.createCopy()), | |||||
| image (other.image), | image (other.image), | ||||
| transform (other.transform) | transform (other.transform) | ||||
| { | { | ||||
| @@ -59,7 +59,7 @@ FillType& FillType::operator= (const FillType& other) | |||||
| if (this != &other) | if (this != &other) | ||||
| { | { | ||||
| colour = other.colour; | colour = other.colour; | ||||
| gradient = (other.gradient != nullptr ? new ColourGradient (*other.gradient) : nullptr); | |||||
| gradient = other.gradient.createCopy(); | |||||
| image = other.image; | image = other.image; | ||||
| transform = other.transform; | transform = other.transform; | ||||
| } | } | ||||
| @@ -1873,8 +1873,7 @@ public: | |||||
| : clip (other.clip), transform (other.transform), font (other.font), | : clip (other.clip), transform (other.transform), font (other.font), | ||||
| fillType (other.fillType), interpolationQuality (other.interpolationQuality), | fillType (other.fillType), interpolationQuality (other.interpolationQuality), | ||||
| state (other.state), transparencyLayerAlpha (other.transparencyLayerAlpha), | state (other.state), transparencyLayerAlpha (other.transparencyLayerAlpha), | ||||
| transparencyLayer (other.transparencyLayer), | |||||
| previousTarget (other.previousTarget != nullptr ? new OpenGLTarget (*other.previousTarget) : nullptr) | |||||
| transparencyLayer (other.transparencyLayer), previousTarget (other.previousTarget.createCopy()) | |||||
| { | { | ||||
| } | } | ||||