Reputation: 747
I'm trying to debug a MIDI issue in a complex iOS / Objective-C software. It appears on this call :
OSStatus s;
MIDIClientRef midi_client_ref;
s = MIDIClientCreate((CFStringRef)@"MIDIPlayerSetup MIDI Client", NULL, NULL,
&midi_client_ref);
Most of the time everything works fine but sometimes the returned OSStatus is a -50 code (bad parameter).
But as you can see and like in many example of MIDIClientCreate on the web, the explicit parameters can't really be the problem. I even tried to have an unique name with no effect.
To orientate my search, I would need to have a more precise idea of what is going on in the underlying client creation that could provoke this bad parameter issue.
Any guess is welcome !
UPDATE : someone got the same issue here and solved it. He says "It was caused by an uninitalised variable.".
That's an indication, but not enough to lead me to my mistake...
Upvotes: 1
Views: 2253
Reputation: 747
I contacted Apple and this is an internal CoreMIDI bug (until iOS8.3 at least) that was unknown until now.
MIDIClientCreate itself will return -50 in only two scenarios:
1) If outClient itself is NULL so in the above you forget to take the address of client.
2) If the MIDI server has an issue getting a process ID back internally
I ensured the address of the client I provide is ok so in my case that is 2).
I then noticed that I had several calls to MIDIGetNumberOfSources();
before the potential bug, so I implemented a sample app with in its delegate :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSLog(@"application:didFinishLaunchingWithOptions:");
for (int i = 0; i < 100000000; i++) {
MIDIGetNumberOfSources();
}
MIDIClientRef client;
OSStatus s = MIDIClientCreate(CFSTR("iMIDI Client"), NULL, NULL, &client);
NSLog(@"OSStatus : %d", (int)s);
return YES;
}
Running the app on iPhone 5 in iOS Simulator with iOS 8.3 (12F69) gives about 50% chances to reproduce the bug each time on my machine.
Upvotes: 1