MessageManagerLock problem

I have a thread that needs to do some gui stuff and then ends. The run method looks something like this:

void MyDialog::run()
{
    MessageManagerLock mmlock;

    label1->setText("some text", dontSendNotification);
}

I get an assertion here:

void Font::getGlyphPositions (const String& text, Array<int>& glyphs, Array<float>& xOffsets) const
{
    // This call isn't thread-safe when there's a message thread running
    jassert (MessageManager::getInstanceWithoutCreating() == nullptr
               || MessageManager::getInstanceWithoutCreating()->currentThreadHasLockedMessageManager());

Debugging this, it seems that getInstanceWithoutCreating is returning a non zero value and that the currentThreadHasLockedMessageManager is false.

Am I doing something wrong? Why isn’t the Message thread locked?

Better use MessageManager::callAsync instead no ?

https://docs.juce.com/master/classMessageManager.html#acfe6da5271c2ab76fdb0414b235ed095

yes, that seems to work, but why doesn’t locking the Message thread work? What is the best practice here?

I can only agree to avoid the MessageManagerLock whenever possible, especially in plugins, where you share the message-thread with the host, it is very easy to accidentally cause a deadlock (or not being able to lock at all). Better use async-callbacks whenever possible. (and check the existence of the objects which you are calling in the callback with a safe-pointer)