aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2011-09-10 01:12:34 -0700
committerChris Robinson <[email protected]>2011-09-10 01:12:34 -0700
commit724ad0d89381456771c672b68b72bb07042b2173 (patch)
treef8b5c8ffcfd64d0ff03cdeb64edceef41852e7c2
parent7a0df8553fbf879f94c372aed3d7b5dfab25ad6c (diff)
Add an option to trap context errors in a debugger
-rw-r--r--Alc/ALc.c8
-rw-r--r--OpenAL32/Include/alError.h2
-rw-r--r--OpenAL32/alError.c17
-rw-r--r--alsoftrc.sample8
4 files changed, 35 insertions, 0 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 339b5907..757514a3 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -34,6 +34,7 @@
#include "alSource.h"
#include "alBuffer.h"
#include "alAuxEffectSlot.h"
+#include "alError.h"
#include "bs2b.h"
#include "alu.h"
@@ -498,6 +499,10 @@ static void alc_init(void)
if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1))
ZScale = -1.0;
+ str = getenv("__ALSOFT_TRAP_AL_ERROR");
+ if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1))
+ TrapALError = AL_TRUE;
+
pthread_key_create(&LocalContext, ReleaseThreadCtx);
InitializeCriticalSection(&ListLock);
ThunkInit();
@@ -569,6 +574,9 @@ static void alc_initconfig(void)
if(DefaultResampler >= RESAMPLER_MAX || DefaultResampler <= RESAMPLER_MIN)
DefaultResampler = RESAMPLER_DEFAULT;
+ if(!TrapALError)
+ TrapALError = GetConfigValueBool(NULL, "trap-al-error", AL_FALSE);
+
ReverbBoost *= aluPow(10.0f, GetConfigValueFloat("reverb", "boost", 0.0f) /
20.0f);
EmulateEAXReverb = GetConfigValueBool("reverb", "emulate-eax", AL_FALSE);
diff --git a/OpenAL32/Include/alError.h b/OpenAL32/Include/alError.h
index 7976e50f..f3a9c12d 100644
--- a/OpenAL32/Include/alError.h
+++ b/OpenAL32/Include/alError.h
@@ -8,6 +8,8 @@
extern "C" {
#endif
+extern ALboolean TrapALError;
+
ALvoid alSetError(ALCcontext *Context, ALenum errorCode);
#ifdef __cplusplus
diff --git a/OpenAL32/alError.c b/OpenAL32/alError.c
index 29d06027..8b95423b 100644
--- a/OpenAL32/alError.c
+++ b/OpenAL32/alError.c
@@ -20,10 +20,14 @@
#include "config.h"
+#include <signal.h>
+
#include "alMain.h"
#include "AL/alc.h"
#include "alError.h"
+ALboolean TrapALError = AL_FALSE;
+
AL_API ALenum AL_APIENTRY alGetError(void)
{
ALCcontext *Context;
@@ -41,5 +45,18 @@ AL_API ALenum AL_APIENTRY alGetError(void)
ALvoid alSetError(ALCcontext *Context, ALenum errorCode)
{
+ if(TrapALError)
+ {
+#ifdef _WIN32
+ /* Safely catch a breakpoint exception that wasn't caught by a debugger */
+ __try {
+ DebugBreak();
+ } __except((GetExceptionCode()==EXCEPTION_BREAKPOINT) ?
+ EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
+ }
+#elif defined(SIGTRAP)
+ kill(getpid(), SIGTRAP);
+#endif
+ }
CompExchangeInt(&Context->LastError, AL_NO_ERROR, errorCode);
}
diff --git a/alsoftrc.sample b/alsoftrc.sample
index 1f749f69..baf0930b 100644
--- a/alsoftrc.sample
+++ b/alsoftrc.sample
@@ -150,6 +150,14 @@
#layout_61CHN = fl=-30, fr=30, fc=0, sl=-90, sr=90, bc=180
#layout_71CHN = fl=-30, fr=30, fc=0, sl=-90, sr=90, bl=-150, br=150
+## trap-al-error:
+# Generates a SIGTRAP signal when an AL context error is generated, on systems
+# that support it. This helps when debugging, while trying to find the cause
+# of a context error. On Windows, a breakpoint exception is generated.
+# Optionally, the __ALSOFT_TRAP_AL_ERROR env var may be set before running the
+# app instead.
+#trap-al-error = false
+
##
## Reverb effect stuff (includes EAX reverb)
##