MidiBuffer::addEvent() divide by zero crash

This is driving me mad…

I have a MidiBuffer in my class ‘midiEvents’ and I’m doing

JUCE_NAMESPACE::uint8 data [4];
data[0] = byte1;
data[1] = byte2;
data[2] = byte3;
		
midiEvents.addEvent (data, 3, 0);

… modifed from juce_AudioUnitWrapper.cpp

I crash in the call to addEvent() with a divide by zero error in ArrayAllocationBase::ensureAllocatedSize. I assume it must be the granularity that is zero but can’t see how it possibly can be, it should be set to 32 on initialisation of MidiBuffer. Any ideas?

… ok, answered my own question. :roll:

The pitfalls of mixing C and C++. The MidiBuffer wasn’t in a class it was in a struct so didn’t get initialised properly. Changed it to a MidiBuffer* and it works now.

Thanks for listening… :oops:

Ouch… yes, definitely best to stick to c++ compilers!