[Bf-blender-cvs] [ca881afef16] blender-v2.83-release: Fix T88877: 2.93: Crash on recent OSX with a non-English locale.
Ankit Meel
noreply at git.blender.org
Mon Jan 17 15:56:40 CET 2022
Commit: ca881afef1631cdd138ccf9af090ca6fb29b3608
Author: Ankit Meel
Date: Fri Oct 29 10:11:04 2021 +0200
Branches: blender-v2.83-release
https://developer.blender.org/rBca881afef1631cdd138ccf9af090ca6fb29b3608
Fix T88877: 2.93: Crash on recent OSX with a non-English locale.
Looks like OSX changed the default format of its locale, which is not
valid anymore for gettext/boost::locale.
Solution based on investigations and patch by Kieun Mun (@kieuns), with
some further tweaks by Ankit Meel (@ankitm), many thanks.
Also add an exception catcher on `std::runtime_error` in
`bl_locale_set()`, since in OSX catching the ancestor `std::exception`
does not work with `boost::locale::conv::conversion_error` and the like
for some reasons.
Reviewed By: #platform_macos, brecht
Maniphest Tasks: T88877
Differential Revision: https://developer.blender.org/D13019
===================================================================
M intern/locale/boost_locale_wrapper.cpp
M intern/locale/osx_user_locale.mm
===================================================================
diff --git a/intern/locale/boost_locale_wrapper.cpp b/intern/locale/boost_locale_wrapper.cpp
index 73433fe7c5e..ede9377b38f 100644
--- a/intern/locale/boost_locale_wrapper.cpp
+++ b/intern/locale/boost_locale_wrapper.cpp
@@ -117,6 +117,13 @@ void bl_locale_set(const char *locale)
#undef LOCALE_INFO
}
+ // Extra catch on `std::runtime_error` is needed for macOS/Clang as it seems that exceptions
+ // like `boost::locale::conv::conversion_error` (which inherit from `std::runtime_error`) are
+ // not caught by their ancestor `std::exception`. See
+ // https://developer.blender.org/T88877#1177108 .
+ catch (std::runtime_error const &e) {
+ std::cout << "bl_locale_set(" << locale << "): " << e.what() << " \n";
+ }
catch (std::exception const &e) {
std::cout << "bl_locale_set(" << locale << "): " << e.what() << " \n";
}
diff --git a/intern/locale/osx_user_locale.mm b/intern/locale/osx_user_locale.mm
index e2f65d39df9..ce694b5fc1e 100644
--- a/intern/locale/osx_user_locale.mm
+++ b/intern/locale/osx_user_locale.mm
@@ -14,7 +14,17 @@ const char *osx_user_locale()
CFLocaleRef myCFLocale = CFLocaleCopyCurrent();
NSLocale *myNSLocale = (NSLocale *)myCFLocale;
[myNSLocale autorelease];
- NSString *nsIdentifier = [myNSLocale localeIdentifier];
+
+ // This produces gettext-invalid locale in recent macOS versions (11.4),
+ // like `ko-Kore_KR` instead of `ko_KR`. See T88877.
+ // NSString *nsIdentifier = [myNSLocale localeIdentifier];
+
+ const NSString *nsIdentifier = [myNSLocale languageCode];
+ const NSString *const nsIdentifier_country = [myNSLocale countryCode];
+ if ([nsIdentifier length] != 0 && [nsIdentifier_country length] != 0) {
+ nsIdentifier = [NSString stringWithFormat:@"%@_%@", nsIdentifier, nsIdentifier_country];
+ }
+
user_locale = ::strdup([nsIdentifier UTF8String]);
[pool drain];
More information about the Bf-blender-cvs
mailing list