diff options
-rw-r--r-- | Alc/ALc.c | 25 | ||||
-rw-r--r-- | alsoftrc.sample | 8 |
2 files changed, 33 insertions, 0 deletions
@@ -25,6 +25,7 @@ #include <stdio.h> #include <memory.h> #include <ctype.h> +#include <signal.h> #include "alMain.h" #include "alSource.h" @@ -399,6 +400,9 @@ ALdouble ConeScale = 0.5; // Localized Z scalar for mono sources ALdouble ZScale = 1.0; +/* Flag to trap ALC device errors */ +static ALCboolean TrapALCError = ALC_FALSE; + /* One-time configuration init control */ static pthread_once_t alc_config_once = PTHREAD_ONCE_INIT; @@ -503,6 +507,10 @@ static void alc_init(void) if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1)) TrapALError = AL_TRUE; + str = getenv("__ALSOFT_TRAP_ALC_ERROR"); + if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1)) + TrapALCError = ALC_TRUE; + pthread_key_create(&LocalContext, ReleaseThreadCtx); InitializeCriticalSection(&ListLock); ThunkInit(); @@ -574,6 +582,9 @@ static void alc_initconfig(void) if(DefaultResampler >= RESAMPLER_MAX || DefaultResampler <= RESAMPLER_MIN) DefaultResampler = RESAMPLER_DEFAULT; + if(!TrapALCError) + TrapALCError = GetConfigValueBool(NULL, "trap-alc-error", ALC_FALSE); + if(!TrapALError) TrapALError = GetConfigValueBool(NULL, "trap-al-error", AL_FALSE); @@ -1050,6 +1061,20 @@ static ALCboolean IsContext(ALCcontext *context) */ ALCvoid alcSetError(ALCdevice *device, ALenum errorCode) { + if(TrapALCError) + { +#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 + } + LockLists(); if(IsDevice(device)) device->LastError = errorCode; diff --git a/alsoftrc.sample b/alsoftrc.sample index baf0930b..b4ce9a40 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-alc-error: +# Generates a SIGTRAP signal when an ALC device error is generated, on systems +# that support it. This helps when debugging, while trying to find the cause +# of a device error. On Windows, a breakpoint exception is generated. +# Optionally, the __ALSOFT_TRAP_ALC_ERROR env var may be set before running +# the app instead. +#trap-alc-error = false + ## 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 |