Component::repaint() is unsafe to call from a thread even if the MessageManager is locked

Component::repaint() is unsafe to call from a thread even if the MessageManager is locked. If you do, on macOS at least, worst case scenario is the paint() call will happen on the thread repaint() was called from, which is bad. Best case scenario is it just won’t do anything.

This comment however implies it’s an ok thing to do if the MessageManager is locked.

    // if component methods are being called from threads other than the message
    // thread, you'll need to use a MessageManagerLock object to make sure its thread-safe.
    JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED

Example code here: https://github.com/FigBug/juce_bugs/blob/master/ThreadedRepaint/Source/MainComponent.cpp

1 Like