title: iOS SDK 4.3 OpenAL alGenSources results in AL_INVALID_OPERATION
body: <p>I'm trying to get to grips with OpenAL, working through a tutorial here: <a href="http://benbritten.com/2008/11/06/openal-sound-on-the-iphone/" rel="nofollow">http://benbritten.com/2008/11/06/openal-sound-on-the-iphone/</a></p>
  
  <p>My problem is that the sound does not play, although there are no iOS errors thrown. There is an OpenAL error though. The code sample below is the body of an IBAction method, and results in an AL_INVALID_OPERATION at alGenSources(1, &amp;sourceID). sourceID reports as NULL.</p>
  
  <p>I've tried this on the device and the simulator.</p>
  
  <p>This code sample seems to be in pretty wide use, but I can't find anybody complaining of this particular problem. Can anybody throw any light on this? Many thanks for any help,</p>
  
  <pre><code> NSString *audioFileName = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"caf"];
  AudioFileID fileID = [self openAudioFile:audioFileName];
  
  UInt32 filesize = [self audioFileSize:fileID];
  unsigned char *outData = malloc(filesize);
  OSStatus result = noErr;
  result = AudioFileReadBytes(fileID, false, 0, &amp;filesize, outData);
  AudioFileClose(fileID);
  
  if (result != 0) {
      NSLog(@"Can't load file..");
  }
  
  NSUInteger bufferID;
  //NSLog(@"bufferID %@", [NSNumber numberWithUnsignedInteger:bufferID]);
  alGenBuffers(1, &amp;bufferID);
  //NSLog(@"bufferID %@", [NSNumber numberWithUnsignedInteger:bufferID]);
  alBufferData(bufferID, AL_FORMAT_STEREO16, outData, filesize, 44100);
  
  [bufferStorageArray addObject:[NSNumber numberWithUnsignedInteger:bufferID]];
  
  alGetError();
  ALuint sourceID;
  alGenSources(1, &amp;sourceID);
  
  if(alGetError() == AL_INVALID_OPERATION) 
  {
      printf("\n++++ Error creating buffers INVALID_OPERATION!!\n");
  
      //exit(1);
  }
  else
  {
      printf("No errors yet.");
  }
  
  alSourcei(sourceID, AL_BUFFER, bufferID);
  
  alSourcef(sourceID, AL_PITCH, 1.0f);
  alSourcef(sourceID, AL_GAIN, 1.0f);
  if (loops) {
      alSourcei(sourceID, AL_LOOPING, AL_TRUE);
  }
  
  [soundDictionary setObject:[NSNumber numberWithUnsignedInt:sourceID] forKey:@"sound"];
  
  if (outData) {
      free(outData);
      outData = NULL;
  }
  
  [self playSound:@"sound"];
  </code></pre>