Dissmiss CallOutBox when closing the window?

I create a CallOutBox to handle color selection in a preferences window as usual:

void mouseDown (const juce::MouseEvent&) override
    auto t = std::make_unique<MyGreatColourSelector> (getColour());
    juce::CallOutBox::launchAsynchronously (std::move (t), getScreenBounds(), nullptr);

But when the preferences window is closed, the CallOutBox remains.

What is the best strategy to force the dismiss in that case?

Have you tried passing a pointer to the window to the third argument of launchAsynchronously? It takes a pointer to a component to be the box’s parent - I’d assume that the box would then be removed when the parent is removed.

I’ve just tried quickly. It works but it can’t be drawn outside the parent’s window now. I would prefer the other behavior. And the arrow position is a bit strange (but it think i could solve that).

I resolved the problem by creating a global tracker of CallOutBox.
Registered CallOutBox are auto-magically dismissed when the owner is destructed.

CallOutBoxRegister.cpp (1.5 KB)
CallOutBoxRegister.hpp (4.3 KB)