summaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2011-09-10 01:23:59 -0700
committerChris Robinson <[email protected]>2011-09-10 01:23:59 -0700
commit23d693cd061041b8dd0a78c7cd058a331f76e253 (patch)
treedefb00b4d2727d8fa47a994fb740ad74ff1afa29 /Alc
parent724ad0d89381456771c672b68b72bb07042b2173 (diff)
Add an option to trap device errors in a debugger
Diffstat (limited to 'Alc')
-rw-r--r--Alc/ALc.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 757514a3..cca3c230 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -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;