[Bug] JUCE 6 - CaretComponent dtor needs to stopTimer

To avoid an assert in the Timer destructor the CaretComponent destructor needs:

CaretComponent::~CaretComponent()
{
    stopTimer();
}

Thanks,

Rail

Where are you hitting this assertion? It will only be triggered if you’re destroying the object derived from Timer on a thread other than the message thread, which in the case of CaretComponent will probably cause all sorts of other issues as you should only really be calling Component methods from the message thread. Perhaps the assertion needs to also check if the calling thread has the MessageManagerLock as this should be safe.

This works too:

Timer::~Timer()
{
    // If you're destroying a timer on a background thread, make sure the timer has
    // been stopped before execution reaches this point. A simple way to achieve this
    // is to add a call to `stopTimer()` to the destructor of your class which inherits
    // from Timer.
    
    if (! (MessageManager::getInstanceWithoutCreating() != nullptr && MessageManager::getInstanceWithoutCreating()->currentThreadHasLockedMessageManager()))
        jassert (MessageManager::existsAndIsCurrentThread() || ! isTimerRunning());

    stopTimer();
}

Rail

1 Like