Bug in MidiOutput::openDevice?

midi

#1

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)


#2

maybe use a scoped pointer to hold it instead?

ScopedPointer<MidiOutput> A( MidiOutput::openDevice(1) );

the days of manually having to call delete are over!


#3

Hello Matkatmusic,

Unfortunately a scoped pointer does not help in this case. Already tried that.


#4

lol don’t make 2 scoped pointers pointing to the same object.


#5

I was about to look at that code anyway on Windows to make it easier to open multiple shared copies of a device, so this should get fixed soon…


#6

Thanks, that sounds very good :slight_smile:


#7

OK this is fixed on develop with commit 508ba42.


#8

Thanks for the quick fix. Just tested, works! :slight_smile: