我已经使用OpenAL为我的应用程序实现了声音。看起来它工作正常,直到我关闭应用程序并尝试清理每个声音相关的对象。基本上我有一个清理方法如下:
public void cleanup(){
//looping through sources and deleting them like this:
alSourceStop(id);
alDeleteSources(id);
//ids of sources and buffers are not the same they are in different classes
//looping through buffers and deleting them like this:
alDeleteBuffers(id);
//destroying context
alcDestroyContext(context);
//closing device
alcCloseDevice(device);
}
当我评论alcCloseDevice
时,我会收到如下消息:
AL lib: (EE) alc_cleanup: 1 device not closed
如果我把它留在原处:
A fatal error has been detected by the Java Runtime Environment ... Failed to write core dump ...
依此类推
我在Windows 7 64位操作系统上使用LWJGL 3.1.0,所有OpenGL和OpenAL相关的东西都由一个线程管理。
我的设置如下:
device = alcOpenDevice((ByteBuffer)null);
ALCCapabilities caps = ALC.createCapabilities(device);
context = alcCreateContext(device, (IntBuffer)null);
alcMakeContextCurrent(context);
AL.createCapabilities(caps);
创建设备和上下文没有问题。
像这样创建缓冲区:
id = alGenBuffers();
try(STBVorbisInfo info = STBVorbisInfo.malloc()){
ShortBuffer buffer = /*decoding ogg here without problem*/
alBufferData(id, info.channels() == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, buffer, info.sample_rate());
}
同时设置源代码和监听器,但我不相信会对它产生任何影响,而不会实际创建任何源和监听器关闭设备导致错误。