MidiBuffer exceptions in processBlock()

#1

Occasionally, the debugger raises exception with what seems to be zero sized message for no appearant reason.
I have the following in processBlock() to deliver midi events produced from Juce components to the DAW Plugin output.

for (MidiBuffer::Iterator i(midiOutDAW); i.getNextEvent(mDAW, time);)
	{
		midiMessages.addEvent(mDAW,time);					//output event to DAW
	};
	midiOutDAW.clear(); 

The MidiBuffer midiOutDAW is defined in PluginProcessor.h and a raw pointer MidiBuffer* is passed to the constructor of components (MidiBuffer* myMidiOutBufferDAW;) that generate the events

mySlider->onValueChange = [this] {
			auto message = MidiMessage::controllerEvent(1, Get_CC(myIndex), (int)mySlider->getValue());
			myMidiOutBufferDAW->addEvent(message, 0);
		};

Is the raw pointer reference threadsafe? If not, what to do?
Thanks for input

0 Likes

#2

From the class reference:
Note that altering the buffer while an iterator is using it will produce undefined behaviour.
So the MidiBuffer is being iterated in the processBlock() and I am adding new data to it from components that belong to the editor. I suppose this is a problem.
How should I be doing this?
I thought queues were there to prevent these kinds of issues?
Any advice greatly appreciated!

0 Likes