Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2015-02-03 15:34:05 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2015-02-03 15:36:15 +0300
commit701a7dcc87f312a207b6652a2afc2e32fe236f34 (patch)
tree7fafd78f0a7c5a03eda6842b03e718069389602c /source/blender/blenfont
parent1667e68797a599c204fefa318df42d434ccb2188 (diff)
Fix T43544: Runtime Error when Locale is not valid
This is not a real fix and only prevents crash, textures IO might be not working totally correct if they're unicode path or so. Proper solution would be to detect which locale we can use and set LANG, LC_ALL and friends.
Diffstat (limited to 'source/blender/blenfont')
-rw-r--r--source/blender/blenfont/intern/blf_lang.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/source/blender/blenfont/intern/blf_lang.c b/source/blender/blenfont/intern/blf_lang.c
index 10614e8ca59..8951ef50607 100644
--- a/source/blender/blenfont/intern/blf_lang.c
+++ b/source/blender/blenfont/intern/blf_lang.c
@@ -33,6 +33,10 @@
#include <stdlib.h>
#include <string.h>
+#ifndef _WIN32
+# include <locale.h>
+#endif
+
#include "RNA_types.h"
#include "BLF_translation.h" /* own include */
@@ -189,7 +193,33 @@ void BLF_lang_init(void)
{
#ifdef WITH_INTERNATIONAL
const char * const messagepath = BKE_appdir_folder_id(BLENDER_DATAFILES, "locale");
+#endif
+
+ /* Make sure LANG is correct and wouldn't cause std::rumtime_error. */
+#ifndef _WIN32
+ /* TODO(sergey): This code only ensures LANG is set properly, so later when
+ * Cycles will try to use file system API from boost there'll be no runtime
+ * exception generated by std::locale() which _requires_ having proper LANG
+ * set in the environment.
+ *
+ * Ideally we also need to ensure LC_ALL, LC_MESSAGES and others are also
+ * set to a proper value, but currently it's not a huge deal and doesn't
+ * cause any headache.
+ *
+ * Would also be good to find nicer way to check if LANG is correct.
+ */
+ const char *lang = getenv("LANG");
+ if(lang != NULL) {
+ char *old_locale = setlocale(LC_ALL, NULL);
+ if (setlocale(LC_ALL, lang) == NULL) {
+ setenv("LANG", "C", 1);
+ printf("Warning: Falling back to the standard locale (\"C\")\n");
+ }
+ setlocale(LC_ALL, old_locale);
+ }
+#endif
+#ifdef WITH_INTERNATIONAL
if (messagepath) {
bl_locale_init(messagepath, TEXT_DOMAIN_NAME);
fill_locales();