-
Notifications
You must be signed in to change notification settings - Fork 758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Topic/coremidi crash fix #1147
Topic/coremidi crash fix #1147
Conversation
…pile. On mac, sclang can crash when MIDI is initialized after a library recompile (on my machine and a few others I've used, this occurs 100% of the time). This crash occurs in prListMIDIEndpoints, due to a null devname or endname because of a previous call that errors out. Trivially, we can stop the crash by protecting against cases where MIDIObjectGetStringProperty doesn't return a proper result. These calls were ultimately failing because calling MIDIClientCreate a second time after called MIDIClientDispose results in that call failing. The documentation is unclear exactly how CoreMIDI expects these to be called, but it implies that the normal lifetime of a client is one per app launch ("It is not essential to call this function; the CoreMIDI framework will automatically dispose all MIDIClients when an application terminates.") - in any case, our use case is pretty simple, and a crash is a crash..... This fixes the core problem by only initializing MIDI once, and then keeping that MIDI client for the rest of sclang's lifetime. Effectively, gMIDIClient becomes a singleton.
didn't check the code, but maybe it would make sense to provide a |
There's already a de-initialization function, but that's precisely the problem. After initializing the midi client, then de-initializing, future attempts to initialize will fail -- causing bad bugs. We're barely using the MIDI client - it's only required as an argument to a few other calls - so there's not much massaging of code on the SC side to be done. I suspect it's either not intended to be repeatedly created and destroyed as we're doing, or if it is, nobody is doing it except for us and there are lurking bugs. Regardless, I don't see any reason why we can't just carry it over between Library rebuilds. Note that we still init and de-init midi connections we make between library recompiles - this seems to work just fine. |
What's the best way to test this ? create a midi responder and recompile the library, repeat vigorously ? |
arg. this is so old that it won't build with my current up to date qt5 sc set up. |
A library rebuild is supposed to behave exactly like a restart of sclang, so maybe better not. |
@telephon - You're right - but, this is seemingly a problem with the CoreMIDI API's, so there's no other option to avoid the crash. AFAICT once we've called MIDIClientDispose, we can't call MIDIClientCreate again. In lieu of a specific problem happening because of the client re-use, it seems better to opt for avoiding the crash.... |
@crucialfelix - I saw this all the time in a workflow that looked like: (a) compile lang (b) create and init client (c) use midi, (d) recompile (e) repeat..... In an afternoon of working, I would see this crash ten or twelve times - not on every recompile, but it was not uncommon either. |
… into topic/coremidi-crash-fix
@crucialfelix - I just updated this branch but didn't see any merge conflicts or anything - what's the build problem you're seeing? |
I've experienced the bug myself in the past. Very happy to see a potential If I check out the branch I couldn't just build it because I have to switch Or we just merge it and test in master.
|
I'm okay with merging and testing in master - I would consider this a safe fix. @telephon - can you merge if you're okay, or else let us know if there are any problems related to reusing the MIDI client? |
I don't use MIDI, so I can't test. But I think this fix for now is better than nothing. |
@scztt many thanks for fixing this longstanding issue. i can confirm that it is now fixed. in my previous build (21c661b) and earlier it was easy to crash sc with...
and you'd get this even without any midi gear connected. |
All Hail @scztt Exterminator of The Bug ! |
No description provided.