It seems to me, there is a bug in MidiOutput::openDevice. I am on Win 7 on a JUCE Gui application.
When you open the same Midi device twice and then delete both pointers, you are getting an exception. Here is the code, which causes the problem:
MidiOutput* A = juce::MidiOutput::openDevice(1);
MidiOutput* B = juce::MidiOutput::openDevice(1);
delete A;
delete B;
I am pretty sure this did not happen on JUCE 4.3. Because the error started to appear, when I migrated from JUCE 4.3 to JUCE 5.3.
Or maybe the function is not supposed to be used that way?
In that case I think it would be good to change the description of the openDevice function. Because it says: “This will return a MidiOutput object if it manages to open it. You can then send messages to this device, and delete it when no longer needed.”
Maybe is it should also say: “But note that this function only gives you a reference to the MidiOutput object. So make sure not to delete it twice (in case you opened it twice)”