c++audioopenal

OpenAL alGenBuffers Error Code 40964 Solution


I am a noob for openAL programming, there is an error which I encountered.

My code is following:

ALuint test_buffer[10];
ALenum error;
alGenBuffers(10,test_buffer);
if((error=alGetError())!=AL_NO_ERROR){
  std::cout<<"alGenBuffer Error:"<<error<<std::endl;
}

Then I get error code 40964. How to solve it?


Solution

  • Firstly you need to look-up the result in the openAL constants, then print a more meaningful error. Something along the lines of:

    public static String openAlErrorToString(int err) {
    switch (err) {
      case AL_NO_ERROR: return "AL_NO_ERROR";
      case AL_INVALID_DEVICE: return "AL_INVALID_DEVICE";
      case AL_INVALID_CONTEXT: return "AL_INVALID_CONTEXT";
      case AL_INVALID_ENUM: return "AL_INVALID_ENUM";
      case AL_INVALID_VALUE: return "AL_INVALID_VALUE";
      case AL_OUT_OF_MEMORY: return "AL_OUT_OF_MEMORY";
      /* ... */
      default:
        return "Unknown error code";
    }
    

    A quick google reveals that 40964 could be AL_INVALID_OPERATION or AL_INVALID_VALUE.

    From the docs for alGenBuffers, this only pushes:

    So your AL_INVALID_OPERATION could be an error from earlier in your program. Perhaps you have a left-over error code on stack? Call alGetError() before your buffer initialisation to rule that out.