From fc7099a9057ee962ea4fd43bf049396d86065cf0 Mon Sep 17 00:00:00 2001 From: Armada Date: Sat, 15 Jun 2013 13:21:57 +0200 Subject: 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. --- Source/Core/VideoCommon/Src/TextureConversionShader.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoCommon/Src/TextureConversionShader.cpp') diff --git a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp index 539d8799f9..573713a198 100644 --- a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp +++ b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp @@ -6,6 +6,9 @@ #include #include #include +#ifdef __APPLE__ + #include +#endif #include "TextureConversionShader.h" #include "TextureDecoder.h" @@ -804,7 +807,8 @@ void WriteZ24Encoder(char* p, API_TYPE ApiType) const char *GenerateEncodingShader(u32 format,API_TYPE ApiType) { - 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; @@ -888,7 +892,8 @@ const char *GenerateEncodingShader(u32 format,API_TYPE ApiType) if (text[sizeof(text) - 1] != 0x7C) PanicAlert("TextureConversionShader generator - buffer too small, canary has been eaten!"); - setlocale(LC_NUMERIC, ""); // restore locale + uselocale(old_locale); // restore locale + freelocale(locale); return text; } -- cgit v1.2.3 From 9594cac42c7612977e1ef4c8493e52037f15abf9 Mon Sep 17 00:00:00 2001 From: Armada Date: Sun, 16 Jun 2013 14:34:23 +0200 Subject: Build fix: Android NDK doesn't support any locale switching. Also, Mac OS X doesn't support DX9. --- Source/Core/VideoCommon/Src/TextureConversionShader.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/Src/TextureConversionShader.cpp') diff --git a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp index 573713a198..40873b903e 100644 --- a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp +++ b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp @@ -807,8 +807,10 @@ void WriteZ24Encoder(char* p, API_TYPE ApiType) const char *GenerateEncodingShader(u32 format,API_TYPE ApiType) { +#ifndef ANDROID 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 +#endif text[sizeof(text) - 1] = 0x7C; // canary char *p = text; @@ -891,9 +893,11 @@ const char *GenerateEncodingShader(u32 format,API_TYPE ApiType) if (text[sizeof(text) - 1] != 0x7C) PanicAlert("TextureConversionShader generator - buffer too small, canary has been eaten!"); - + +#ifndef ANDROID uselocale(old_locale); // restore locale freelocale(locale); +#endif return text; } -- cgit v1.2.3