thestk / rtmidi

A set of C++ classes that provide a common API for realtime MIDI input/output across Linux (ALSA & JACK), Macintosh OS X (CoreMIDI) and Windows (Multimedia)
Other
979 stars 269 forks source link

CoreAudio: Crash in getPortCount() #262

Open jkeller51 opened 3 years ago

jkeller51 commented 3 years ago

Expected behavior: getPortCount() returns the number of ports

Actual behavior: getPortCount() causes a crash

Debug info macOS 11.4, Xcode 12.5.1

The crash happens if an NSAlert is run modally just before calling getPortCount(). This causes the main thread to halt until the user closes the alert. When the main thread continues, the crash happens in

unsigned int MidiInCore :: getPortCount()
{
  CFRunLoopRunInMode( kCFRunLoopDefaultMode, 0, false );
  return MIDIGetNumberOfSources();
}

on the line

CFRunLoopRunInMode( kCFRunLoopDefaultMode, 0, false );

If I place a breakpoint on this line just before it executes, the NSAlert previously created is still visible. If I single-step, the application crashes. Xcode does not show any exceptions, it's almost like the app just decides to exit on that line.

jkeller51 commented 3 years ago

Does anyone know the justification for that line? I will try removing that line on my local copy and see if everything still works.

jkeller51 commented 3 years ago

My bad: Fork was out of date, when I pulled from upstream and tested again, the crash no longer happened.

jkeller51 commented 3 years ago

I spoke too soon. The issue is still happening now, but in MidiOutCore :: getPortCount()