OpenAL alGenBuffers 错误代码 40964 解决方法

OpenAL alGenBuffers Error Code 40964 Solution

我是 openAL 编程的菜鸟,我遇到了一个错误。

我的代码如下:

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

然后我得到错误代码 40964。 如何解决?

首先你需要在openAL常量中查找结果,然后打印一个更有意义的错误。大致如下:

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";
}

快速 google 显示 40964 可能是 AL_INVALID_OPERATIONAL_INVALID_VALUE

the docsalGenBuffers,这只会推动:

AL_INVALID_VALUE The buffer array isn't large enough to hold the number of buffers requested. AL_OUT_OF_MEMORY There is not enough memory available to generate all the buffers requested.

AL_INVALID_OPERATION 可能是您程序早期的错误。也许您在堆栈上有遗留的错误代码?在缓冲区初始化之前调用 alGetError() 来排除这种情况。