ASSERT_MESSAGE_MANAGER_IS_LOCKED_OR_OFFSCREEN on Linux

I'm getting ASSERT_MESSAGE_MANAGER_IS_LOCKED_OR_OFFSCREEN assert on Linux. On Windows same code runs without assertion.

How can I check if current thread is same as message thread and if not start method in message thread.

C# equivalent code of what I want:


if (this.InvokeRequired)
{
    this.Invoke(new AddLineDelegate(AddLine), new object[] { "bla bla" });
}
else
{
    AddLine("bla bla");
}

There are loads of ways to invoke something on the message thread.. CallbackMessage, AsyncUpdater, MessageManager::callAsync, etc etc

Thank you. Exactly what I needed.

I used this and it worked:


void MainForm::LogAdd_int(const juce::String& line)
{
    _Log.add(line);
    if (_LogWindow != nullptr)
    {
        ((Form_Log*)_LogWindow->getContentComponent())->AddLog(line);
    }
}
void MainForm::LogAdd(const juce::String& line)
{
    std::function<void(void)> lambda = [this, line]()
    {
        this->LogAdd_int(line);
    };
    juce::MessageManager::callAsync(lambda);
}

You could avoid a lot of boilerplate by not assigning it to a local variable there.

Also, be very careful with lambdas that capture 'this' - it could be called later on, after your component has been deleted..