Search code examples
iphoneiphone-sdk-3.0audio

AudioSessionInitialize returning inscrutable error code


I'm calling AudioSessionInitialize like so

OSStatus result = AudioSessionInitialize(NULL,NULL,interruptionListener,NULL);

and getting the result 0xbfffde94 (i.e. -1073750040) which doesn't match anything in the documentation, which are all readable 4CC's like '!ini' and so forth.

The good news is that it seems like the call worked. Nevertheless, can anyone shed light on this error code?

EDIT: The above error code is returned in the simulator. On the device the error code is 2fffe810.


Solution

  • I figured it out. I'm an idiot. There was an error in the macro I had wrapping the call & reporting the error, which called the AudioSessionInitialize twice. That doesn't quite explain the error code I saw, but it sure isn't worth wondering about.

    UPDATE: Actually this is pretty slapstick so I'm going to explain.

    The offending macro was originally:

    #define CHECK(S) { OSStatus err = (S); if (S) printf("Error %x at \"%s\"\n", err, #S);}
    

    so bug #1 is the if (S) which should be if if (err). Hence I'm repeating every call to the audio system, which explains various other weird things, so I'm very happy I tried to figure out what had seemed like a harmless anomaly. In this case the second call complained that the audio session was already initialized.

    But why the weird error code? I wanted to see the 4CC's so I changed the macro to this, carrying the error along:

    #define CHECK(S) { OSStatus err[2] = {S,0}; if (S) printf("Error %x '%4s' at \"%s\"\n", err, &err, #S); }
    

    (The second OSStatus of 0 terminates the string defined by the 4CC first OSStatus, so I can print it with format %s.) But I forgot to change err to err[0], so it was indeed printing the address of the err array. This I'm pretty sure is correct now:

    #define CHECK(S) { OSStatus err[2] = {S,0}; if (*err) printf("Error %x '%4s' at \"%s\"\n", *err, err, #S); }