cui/source/options/optcolor.cxx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
New commits: commit 7365ace31b1943f06e0ecc9164ba931a0e9030f9 Author: Tor Lillqvist <t...@collabora.com> AuthorDate: Thu Feb 23 12:29:48 2023 +0200 Commit: Tor Lillqvist <t...@collabora.com> CommitDate: Mon Apr 24 11:58:12 2023 +0200 Don't call CuiResId() in a global static variable initialiser Instead, have a function that returns a reference to a local static variable. That local static is then initialised only when the function is called for the first time. Calling CuiResId() in a global initialiser is a bit questionable, and causes an uncaught exception when LO core is used in a WASM app. Possibly it would also have been problematic on other uncommon platforms. Change-Id: I4fd799ba3aa8d63fd3db1eb8cf6211aeed904ed2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147512 Tested-by: Tor Lillqvist <t...@collabora.com> Reviewed-by: Tor Lillqvist <t...@collabora.com> (cherry picked from commit 6f29310fe83873c7d6844cf5e3089ca981e147db) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150149 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/cui/source/options/optcolor.cxx b/cui/source/options/optcolor.cxx index eb13b442232a..112be3ea215c 100644 --- a/cui/source/options/optcolor.cxx +++ b/cui/source/options/optcolor.cxx @@ -160,9 +160,13 @@ const vEntryInfo[] = }; // Maps the names of default color schemes to the corresponding TranslateId -std::map<OUString, OUString> const vColorSchemes = { - {"COLOR_SCHEME_LIBREOFFICE_AUTOMATIC", CuiResId(RID_COLOR_SCHEME_LIBREOFFICE_AUTOMATIC)}, - {"COLOR_SCHEME_LIBREOFFICE_DARK", CuiResId(RID_COLOR_SCHEME_LIBREOFFICE_DARK)} +const std::map<OUString, OUString> &getColorSchemes() +{ + static std::map<OUString, OUString> const vColorSchemes = { + {"COLOR_SCHEME_LIBREOFFICE_AUTOMATIC", CuiResId(RID_COLOR_SCHEME_LIBREOFFICE_AUTOMATIC)}, + {"COLOR_SCHEME_LIBREOFFICE_DARK", CuiResId(RID_COLOR_SCHEME_LIBREOFFICE_DARK)} + }; + return vColorSchemes; }; // If the color scheme name has a translated string, then return the translation @@ -170,8 +174,8 @@ std::map<OUString, OUString> const vColorSchemes = { // For non-translatable color schemes, the ID and the name are the same OUString lcl_SchemeIdToTranslatedName(const OUString& sSchemeId) { - auto it = vColorSchemes.find(sSchemeId); - if (it != vColorSchemes.end()) + auto it = getColorSchemes().find(sSchemeId); + if (it != getColorSchemes().end()) return it->second; return sSchemeId; } @@ -180,7 +184,7 @@ OUString lcl_SchemeIdToTranslatedName(const OUString& sSchemeId) // For non-translatable color schemes, the ID and the name are the same OUString lcl_TranslatedNameToSchemeId(const OUString& sName) { - for (auto it = vColorSchemes.begin(); it != vColorSchemes.end(); ++it) + for (auto it = getColorSchemes().begin(); it != getColorSchemes().end(); ++it) if (it->second == sName) return it->first; return sName;