AudioProcessor::processBlock(), MessageManagerLock and crashes

Hi, I'm creating a plugin which GUI react to some midi messages, like BPM or host time. I'm pretty newbie with threads, but I know that if I want to call to a Component::repaint() or Component::resized() I must create a MessageManagerLock instance, right? The problem is that doing it in AudioProcessor:processBlock() crash the plugin and the host.

My code is something like this:


void MyPluginAudioProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& midiMessages)

      const MessageManagerLock mmLock;

     // someconditions is calculated before the next line

      if (someconditions == true) pMainBar->repaint();


If you comment everything except the mmLock line, it still crash. If you dont place the MessageManagerLock, Component's assertion occurs.


Please, what am I doing wrong?


You should, or rather must not:

- have possibly locking calls in processBlock/processBlockBypassed

- have GUI updates in processBlock/processBlockBypassed

Because this could hang the thread for too long, hence fail to match the real-time deadlines for the audio (and audio will jitter, the audio host will complain with possibly annoying dialogs etc.)


You should handle updates of your UI from another thread, for example with a Timer.

Yes, pay attention to the second last paragraph of the description for AudioProcessor::processBlock (see here:

Be very careful about what you do in this callback - it's going to be called by the audio thread, so any kind of interaction with the UI is absolutely out of the question. If you change a parameter in here and need to tell your UI to update itself, the best way is probably to inherit from a ChangeBroadcaster, let the UI components register as listeners, and then call sendChangeMessage() inside the processBlock() method to send out an asynchronous message. You could also use the AsyncUpdater class in a similar way.

Also take a look at this thread:

Thank you, it's a pretty interesting thread. Solved :)