Midi thread not exiting nicely on windows


Hi Jules,

When I “quit” my application with a call to some emergency function such “FatalAppExit” in the audio callback, the system basically locks up. Not completely, but it is extremely hard to regain control of the computer : the program is still running with a single thread remaining, pumping all the cpu. Apparentely, it is the midiin callback that enters an endless loops : it is receiving a 0-length sysex , calls writeFinishedBlocks etc, and then the midicallback is called again with a 0-length sysex etc, endlessly. As it is very high priority stuff that explains the computer lockup. The solution is just to not call writeFinishedBlocks when hdr->dwBytesRecorded is zero – I don’t know if it is a correct solution or if it will break some sysex stuff:

void handleSysEx (MIDIHDR* const hdr, const uint32 timeStamp) { if (isStarted && hdr->dwBytesRecorded != 0) { concatenator.pushMidiData (hdr->lpData, hdr->dwBytesRecorded, convertTimeStamp (timeStamp), input, callback); writeFinishedBlocks(); } }

However this test used to be there in older juce release, in handleSysEx()

(This is on windows 7 btw, the audio / midi interface is an echo audiofire)


Sounds like a soundcard bug to me, but that looks like a reasonable workaround for it, thanks!


Thanks for the workaround !