From ddc2f9cc4c92a550cba68ecf84e4bd932de139ce Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 14 May 2018 17:08:48 +0100 Subject: [PATCH] Added an assertion to ScopedPointer to catch people resetting it to itself --- modules/juce_core/memory/juce_ScopedPointer.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/juce_core/memory/juce_ScopedPointer.h b/modules/juce_core/memory/juce_ScopedPointer.h index 186889366a..3d1222cefc 100644 --- a/modules/juce_core/memory/juce_ScopedPointer.h +++ b/modules/juce_core/memory/juce_ScopedPointer.h @@ -162,6 +162,12 @@ public: object = newObject; ContainerDeletePolicy::destroy (oldObject); } + else + { + // You're trying to reset this ScopedPointer to itself! This will work here as ScopedPointer does an equality check + // but be aware that std::unique_ptr won't do this and you could end up with some nasty, subtle bugs! + jassertfalse; + } } /** Sets this pointer to a new object, deleting the old object that it was previously pointing to if there was one. */