Bluetooth MIDI (WinRT) - Thread hangs if device is deleted while receiving data

Hey guys, I’m facing a rather annoying problem here.

I’m using the WinRT MIDI implementation in my application to connect to a BLE MIDI device. It’s mostly working as expected, but if I close my application while the MIDI device is actively sending messages, the Message Thread hangs.

This seems to happen on this line 76 in juce_win32_WinRTWrapper.h:

void release() { if (p != nullptr) p->Release(); }

I can also reproduce this with the MidiDemo application by connecting a Seaboard Block via Bluetooth and setting JUCE_USE_WINRT_MIDI=1 in the Projucer. If the seaboard is sending MIDI messages when the application is closed, it will hang.

I can’t really figure out how to debug this further, since the hang is happening inside the Release function of the COM class.