MidiOutput::openDevice returns non-existing object

What’s the expected behavior for MidiOutput::openDevice when the device can not be found?

I would assume I get back nullptr, but on Windows, openDevice returns a non-existent device when passing a gibberish String as identifier. On Mac, it returns nullptr

I stepped through juce_midi_windows.cpp, and on line 1977, creating the wrapper doesn’t result in any errors.

Am I misunderstanding how this should work?

I’m sure you’ve referred to the documentation which states, “If the device can't be opened, this will return an empty object.”. If the implementation matches the documentation then a nullptr (empty unique_ptr) should be returned if the requested port can’t be open.

Unless there has been a recent change to this code, I would be surprised if it doesn’t behave as expected, as it’s been in use for quite some time. But, otoh, it could be a real bug in JUCE which just hasn’t been tickled yet. :slight_smile:

So I can recreate this on multiple Windows machines, on the latest JUCE version, just by starting a new audio app with the Projucer and adding

auto output = juce::MidiOutput::openDevice( "gibberish" );
jassert ( output == nullptr );

The jassert will hit because output is not nullptr but contains a nameless MidiOutput object.

This feels like a bug

Hi, works fine for me and a nullptr is returned. I’m still on Juce 7 though.