MidiOutput::sendMessageNow doesn't check for MIDIERR_NOTREADY


#1

Hi,

On windows 7 x64, when sending a lot of MIDI messages to a MidiOutput, it can overflow the output device driver and cause a nasty crash.

For example, if you install loopMIDI http://www.tobias-erichsen.de/software/loopmidi.html and write a small JUCE program that floods its MIDI port with noteOns/noteOffs while another app (such as MidiOx) listens to the port, it will crash your machine. I can send you a test app if you need to.

We couldn't reproduce on win8, and by looking at the memory dump of the crash it seems the windows function the crash appears in has been deprecated in win8, so this is only windows7 and probably xp too.

There seems to be nothing wrong in the driver's code. I guess it's a windows bug (or feature...).

We managed to work around the problem by modifying MidiOutput::sendMessageNow in juce_win32_Midi.cpp and applying a retry pattern to midiOutShortMsg:

for(res = MIDIERR_NOTREADY, j = 0; j < MAX_RETRY_COUNT && res == MIDIERR_NOTREADY; ++j)
{
  res = midiOutShortMsg (handle->handle, *(unsigned int*) message.getRawData());
  if(res == MIDIERR_NOTREADY)
  {
    Sleep(1);
  }
}

Could you possibly apply this kind of check to the tip?

cheers.


#2

Thanks! I'll take a look..


#3

Hi Adrien,

I'd be highly interested in your test-application.  This should definately not happen

with my driver...

Best regards,

Tobias