1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 06:52:34 +02:00

rwengine: delete OpenAL buffers and sources before OpenAL shutdown

OpenAL printing
```
AL lib: (WW) FreeContext: (0x614000052440) Deleting 22 Sources
AL lib: (WW) FreeDevice: (0x62d0001f4400) Deleting 22 Buffers
```
at program shutdown is actually a warning that not all sources and
buffers were deleted.

Included suggestions from @ShFil119
This commit is contained in:
Anonymous Maarten 2018-08-23 12:10:13 +02:00 committed by Daniel Evans
parent 26398ca636
commit 372381843c
4 changed files with 28 additions and 10 deletions

View File

@ -15,6 +15,11 @@ SoundBuffer::SoundBuffer() {
alCheck(alSourcei(source, AL_LOOPING, AL_FALSE));
}
SoundBuffer::~SoundBuffer() {
alCheck(alDeleteSources(1, &source));
alCheck(alDeleteBuffers(1, &buffer));
}
bool SoundBuffer::bufferData(SoundSource& soundSource) {
alCheck(alBufferData(
buffer,

View File

@ -11,6 +11,7 @@
/// sound instance.
struct SoundBuffer {
SoundBuffer();
~SoundBuffer();
bool bufferData(SoundSource& soundSource);
bool isPlaying() const;

View File

@ -43,13 +43,7 @@ SoundManager::SoundManager(GameWorld* engine) : _engine(engine) {
}
SoundManager::~SoundManager() {
// De-initialize OpenAL
if (alContext) {
alcMakeContextCurrent(nullptr);
alcDestroyContext(alContext);
}
if (alDevice) alcCloseDevice(alDevice);
deinitializeOpenAL();
}
bool SoundManager::initializeOpenAL() {
@ -76,7 +70,7 @@ bool SoundManager::initializeOpenAL() {
return true;
}
bool SoundManager::initializeAVCodec() {
void SoundManager::initializeAVCodec() {
#if defined(RW_DEBUG) && defined(RW_VERBOSE_DEBUG_MESSAGES)
av_log_set_level(AV_LOG_WARNING);
#else
@ -88,8 +82,24 @@ bool SoundManager::initializeAVCodec() {
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100)
av_register_all();
#endif
}
return true;
void SoundManager::deinitializeOpenAL() {
// Buffers have to been removed before openAL is deinitialized
sounds.clear();
buffers.clear();
// De-initialize OpenAL
if (alContext) {
alcMakeContextCurrent(nullptr);
alcDestroyContext(alContext);
}
alContext = nullptr;
if (alDevice) {
alcCloseDevice(alDevice);
}
alDevice = nullptr;
}
bool SoundManager::loadSound(const std::string& name,

View File

@ -87,7 +87,9 @@ public:
private:
bool initializeOpenAL();
bool initializeAVCodec();
void initializeAVCodec();
void deinitializeOpenAL();
ALCcontext* alContext = nullptr;
ALCdevice* alDevice = nullptr;