mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-23 14:23:53 +00:00
Added a couple more OpenAL error checks
This commit is contained in:
parent
86a811c736
commit
f3fa05ba2f
1 changed files with 19 additions and 1 deletions
|
@ -11,11 +11,23 @@ using namespace Mangle::Sound;
|
||||||
static void fail(const std::string &msg)
|
static void fail(const std::string &msg)
|
||||||
{ throw str_exception("OpenAL exception: " + msg); }
|
{ throw str_exception("OpenAL exception: " + msg); }
|
||||||
|
|
||||||
static void checkALError(const std::string &msg)
|
/*
|
||||||
|
Check for AL error. Since we're always calling this with string
|
||||||
|
literals, and it only makes sense to optimize for the non-error
|
||||||
|
case, the parameter is const char* rather than std::string.
|
||||||
|
|
||||||
|
This way we don't force the compiler to create a string object each
|
||||||
|
time we're called (since the string is never used unless there's an
|
||||||
|
error), although a good compiler might have optimized that away in
|
||||||
|
any case.
|
||||||
|
*/
|
||||||
|
static void checkALError(const char *where)
|
||||||
{
|
{
|
||||||
ALenum err = alGetError();
|
ALenum err = alGetError();
|
||||||
if(err != AL_NO_ERROR)
|
if(err != AL_NO_ERROR)
|
||||||
{
|
{
|
||||||
|
std::string msg = where;
|
||||||
|
|
||||||
const ALchar* errmsg = alGetString(err);
|
const ALchar* errmsg = alGetString(err);
|
||||||
if(errmsg)
|
if(errmsg)
|
||||||
fail("\"" + std::string(alGetString(err)) + "\" while " + msg);
|
fail("\"" + std::string(alGetString(err)) + "\" while " + msg);
|
||||||
|
@ -154,7 +166,9 @@ OpenAL_Sound::OpenAL_Sound(ALuint buf, int *ref)
|
||||||
|
|
||||||
// Create a source
|
// Create a source
|
||||||
alGenSources(1, &inst);
|
alGenSources(1, &inst);
|
||||||
|
checkALError("creating instance (clone)");
|
||||||
alSourcei(inst, AL_BUFFER, bufferID);
|
alSourcei(inst, AL_BUFFER, bufferID);
|
||||||
|
checkALError("assigning buffer (clone)");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructor used for original (non-cloned) sounds
|
// Constructor used for original (non-cloned) sounds
|
||||||
|
@ -166,6 +180,7 @@ OpenAL_Sound::OpenAL_Sound(SampleSourcePtr input)
|
||||||
|
|
||||||
// Set up the OpenAL buffer
|
// Set up the OpenAL buffer
|
||||||
alGenBuffers(1, &bufferID);
|
alGenBuffers(1, &bufferID);
|
||||||
|
checkALError("generating buffer");
|
||||||
assert(bufferID != 0);
|
assert(bufferID != 0);
|
||||||
|
|
||||||
// Does the stream support pointer operations?
|
// Does the stream support pointer operations?
|
||||||
|
@ -187,7 +202,9 @@ OpenAL_Sound::OpenAL_Sound(SampleSourcePtr input)
|
||||||
|
|
||||||
// Create a source
|
// Create a source
|
||||||
alGenSources(1, &inst);
|
alGenSources(1, &inst);
|
||||||
|
checkALError("creating source");
|
||||||
alSourcei(inst, AL_BUFFER, bufferID);
|
alSourcei(inst, AL_BUFFER, bufferID);
|
||||||
|
checkALError("assigning buffer");
|
||||||
|
|
||||||
// Create a cheap reference counter for the buffer
|
// Create a cheap reference counter for the buffer
|
||||||
refCnt = new int;
|
refCnt = new int;
|
||||||
|
@ -208,6 +225,7 @@ OpenAL_Sound::~OpenAL_Sound()
|
||||||
// We're the last owner. Delete the buffer and the counter
|
// We're the last owner. Delete the buffer and the counter
|
||||||
// itself.
|
// itself.
|
||||||
alDeleteBuffers(1, &bufferID);
|
alDeleteBuffers(1, &bufferID);
|
||||||
|
checkALError("deleting buffer");
|
||||||
delete refCnt;
|
delete refCnt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue