From 92d700f19942ed931de097c558071e18f922a5f6 Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Fri, 30 Sep 2016 09:26:57 -0400 Subject: [PATCH] SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING --- include/SDL_hints.h | 11 +++++++++++ src/thread/windows/SDL_systhread.c | 10 +++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/SDL_hints.h b/include/SDL_hints.h index cd5f0c33e..9c914d0c1 100644 --- a/include/SDL_hints.h +++ b/include/SDL_hints.h @@ -688,6 +688,17 @@ extern "C" { */ #define SDL_HINT_BMP_SAVE_LEGACY_FORMAT "SDL_BMP_SAVE_LEGACY_FORMAT" +/** + * \brief Tell SDL not to name threads on Windows. + * + * The variable can be set to the following values: + * "0" - SDL will raise the 0x406D1388 Exception to name threads. + * This is the default behavior of SDL <= 2.0.4. (default) + * "1" - SDL will not raise this exception, and threads will be unnamed. + * For .NET languages this is required when running under a debugger. + */ +#define SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING "SDL_WINDOWS_DISABLE_THREAD_NAMING" + /** * \brief An enumeration of hint priorities */ diff --git a/src/thread/windows/SDL_systhread.c b/src/thread/windows/SDL_systhread.c index ae525aead..ffad0d805 100644 --- a/src/thread/windows/SDL_systhread.c +++ b/src/thread/windows/SDL_systhread.c @@ -24,6 +24,7 @@ /* Win32 thread management routines for SDL */ +#include "SDL_hints.h" #include "SDL_thread.h" #include "../SDL_thread_c.h" #include "../SDL_systhread.h" @@ -167,8 +168,15 @@ void SDL_SYS_SetupThread(const char *name) { if ((name != NULL) && IsDebuggerPresent()) { - /* This magic tells the debugger to name a thread if it's listening. */ THREADNAME_INFO inf; + + /* C# and friends will try to catch this Exception, let's avoid it. */ + const char *hint = SDL_GetHint(SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING); + if (hint && *hint == '1') { + return; + } + + /* This magic tells the debugger to name a thread if it's listening. */ SDL_zero(inf); inf.dwType = 0x1000; inf.szName = name;