OpenAL cleanUp

Written by Arthur Brainville - - no comments

I have corrected a problem I had with OpenAL. Since I have messed up a bit my commits about it, I havent well commented the fact

Before, clossing the program caused generaly OpenAL to yell "alc_cleanup : device not closed" and generaly a segmentation fault.

It's not the case anymore !

Now, I properly take the time to destroy any sources and buffer lefted opened on OpneAL. Trying to destroy the Context and the device cases the aplication to exit unexpectedly.

Since it happenend whant you deleberately whant to close the program, it wasn't a real issue. The program crashed when you deleberately want it to quit, that made it quit...

If you take a close look at the AnnEngine destructor, you'll se that the last thing freed is AnnAudioEngine, wich is the class that handle Audio initialisation, loading and spatialization. So the rest of the engine was deleted before.

AnnEngine::~AnnEngine()
{
    //delete all stuff created on the engine
    for(unsigned int i(0); i < objects.size(); i++)
    {
        delete objects[i];
        objects.erase(objects.begin()+i);
    }
    delete m_DynamicsWorld;
    delete m_Broadphase;
    delete m_bodyParams;
    delete m_CollisionConfiguration;
    delete m_Dispatcher;
    delete m_Solver;

    delete m_debugDrawer;
    delete m_Keyboard;
    delete m_Mouse;

    delete AudioEngine;
}

Each AnnGameObject also destroy it's own openal souce and buffer

AnnGameObject::~AnnGameObject()
{
    alSourceStop(m_Source);
    alDeleteSources(1,&m_Source);
    alDeleteBuffers(1,&m_Buffer);
}

Now the AnnAudioEngine close properly the buffer for BGM

AnnAudioEngine::~AnnAudioEngine()
{
    shutdownOpenAL();
}
void AnnAudioEngine::shutdownOpenAL()
{
alSourceStop(bgm);
    alDeleteSources(1,&bgm);
    alDeleteBuffers(1,&buffer);
    alcMakeContextCurrent(NULL);
    alcDestroyContext(Context);
    alcCloseDevice(Device);
    alGetError();
}

It's integrated into master but still need some further testing

Classified in : Uncategorized - Tags : none

Write a comment

What is the second letter of the word ecnti?