diff options
| author | Armada <jules.blok@gmail.com> | 2013-06-15 13:21:57 +0200 |
|---|---|---|
| committer | Armada <jules.blok@gmail.com> | 2013-06-16 12:33:13 +0200 |
| commit | fc7099a9057ee962ea4fd43bf049396d86065cf0 (patch) | |
| tree | ccdaf5bdbce24c9366fae3bbd1a988b4e1886d3b /Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp | |
| parent | 825c5ca09a999aa492bd1137babef5540ff5956e (diff) | |
Set the locale per-thread instead of globally when generating shaders. Add cross-compatible versions of newlocale, uselocale and freelocale.
This commit fixes a rare race condition when generating shaders because setlocale is global.
Diffstat (limited to 'Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp')
| -rw-r--r-- | Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp index 37da0b7216..f46cf43bd2 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp @@ -4,6 +4,10 @@ #include <map> #include <set> +#include <locale.h> +#ifdef __APPLE__ + #include <xlocale.h> +#endif #include "Common.h" #include "Hash.h" @@ -155,7 +159,8 @@ static LPDIRECT3DPIXELSHADER9 CreateCopyShader(int copyMatrixType, int depthConv // this should create the same shaders as before (plus some extras added for DF16), just... more manageably than listing the full program for each combination char text[3072]; - setlocale(LC_NUMERIC, "C"); // Reset locale for compilation + locale_t locale = newlocale(LC_NUMERIC_MASK, "C", NULL); // New locale for compilation + locale_t old_locale = uselocale(locale); // Apply the locale for this thread text[sizeof(text) - 1] = 0x7C; // canary char* p = text; @@ -215,7 +220,8 @@ static LPDIRECT3DPIXELSHADER9 CreateCopyShader(int copyMatrixType, int depthConv if (text[sizeof(text) - 1] != 0x7C) PanicAlert("PixelShaderCache copy shader generator - buffer too small, canary has been eaten!"); - setlocale(LC_NUMERIC, ""); // restore locale + uselocale(old_locale); // restore locale + freelocale(locale); return D3D::CompileAndCreatePixelShader(text, (int)strlen(text)); } |
