Assert in WeakReference

When i close my app, i get this assert

    else
            {
                // You're trying to create a weak reference to an object that has already been deleted!!
              jassert (sharedPointer->get() != 0);  <---------------
            }

because of this:


        // (NB: there are obscure situations where a childShowing = false, but it still has the focus)
        if (currentlyFocusedComponent == child || child->isParentOf (currentlyFocusedComponent))
        {
            const WeakReference<Component> thisPointer (this);   <------

            giveAwayFocus (sendChildEvents || currentlyFocusedComponent != child);

            if (thisPointer == 0)
                return child;

In my App i add a children (a ViewPort (which also owns a component) ) to a component (BottomComponentPlaceHolder), but BottomComponentPlaceHolder is not the owner of the Children. The owner is MainEditor which is the parent of BottomComponentPlaceHolder

CallStack

juce::WeakReference<juce::Component>::Master::operator()(juce::Component * const object=0x02f4c1f0) Line 169 + 0x65 bytes C++ juce::Component::getWeakReference() Line 434 C++ juce::WeakReference<juce::Component>::WeakReference<juce::Component>(juce::Component * const object=0x02f4c1f0) Line 81 + 0x40 bytes C++ juce::Component::removeChildComponent(const int index=1, bool sendParentEvents=false, const bool sendChildEvents=true) Line 1374 + 0xc bytes C++ juce::Component::~Component() Line 417 + 0x1b bytes C++ MainEditor::BottomComponentPlaceHolder::~BottomComponentPlaceHolder() Line 287 + 0x8 bytes C++ MainEditor::BottomComponentPlaceHolder::`scalar deleting destructor'() + 0x14 bytes C++ juce::ScopedPointer<MainEditor::BottomComponentPlaceHolder>::~ScopedPointer<MainEditor::BottomComponentPlaceHolder>() Line 83 + 0x2e bytes C++ MainEditor::~MainEditor() Line 877 + 0x12 bytes C++ MainEditor::`scalar deleting destructor'() + 0x14 bytes C++ juce::Component::SafePointer<juce::Component>::deleteAndZero() Line 2060 + 0x2e bytes C++ juce::ResizableWindow::setContentComponent(juce::Component * const newContentComponent=0x00000000, const bool deleteOldOne=true, const bool resizeToFit=false) Line 116 C++ StandaloneFilterWindow::deleteFilter() Line 603 C++ StandaloneFilterWindow::~StandaloneFilterWindow() Line 326 C++ StandaloneFilterWindow::`scalar deleting destructor'() + 0x14 bytes C++ MainApplication::shutdown() Line 166 + 0x23 bytes C++ juce::JUCEApplication::shutdownApp() Line 194 C++ juce::JUCEApplication::main(const juce::String & commandLine={...}) Line 233 + 0xf bytes C++

Ah, very subtle… thanks. I think it should look like this:

[code] if (currentlyFocusedComponent == child || child->isParentOf (currentlyFocusedComponent))
{
if (sendParentEvents)
{
const WeakReference thisPointer (this);

            giveAwayFocus (sendChildEvents || currentlyFocusedComponent != child);

            if (thisPointer == 0)
                return child;

            grabKeyboardFocus();
        }
        else
        {
            giveAwayFocus (sendChildEvents || currentlyFocusedComponent != child);
        }
    }[/code]