From 27b55030e26e93c5e8d9e7e21206c8709d46ff22 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 28 Mar 2016 15:30:00 -0300 Subject: [PATCH] Fix bug pressing warning icon to add palette color when active locale is non-English It looks like Allegro library was changing the locale to the active one, and it can break things like strtod() (which is used to convert colors from string format in AddColor command). In this case, if we added a HSV color with double floating-point precision, it was added incorrectly because strtod() wasn't taking the decimal part. --- src/allegro/src/x/xkeyboard.c | 2 ++ src/main/main.cpp | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/allegro/src/x/xkeyboard.c b/src/allegro/src/x/xkeyboard.c index 1697d601b..f121e628b 100644 --- a/src/allegro/src/x/xkeyboard.c +++ b/src/allegro/src/x/xkeyboard.c @@ -697,9 +697,11 @@ static int x_keyboard_init(void) #ifdef ALLEGRO_XWINDOWS_WITH_XIM /* Otherwise we are restricted to ISO-8859-1 characters. */ +/* [dacap] Don't call setlocale() if (setlocale(LC_ALL, "") == NULL) { TRACE(PREFIX_W "Could not set default locale.\n"); } +*/ /* TODO: is this needed? modifiers = XSetLocaleModifiers("@im=none"); diff --git a/src/main/main.cpp b/src/main/main.cpp index 94cfcfe47..e69932a2e 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2016 David Capello // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -22,6 +22,7 @@ #include "she/scoped_handle.h" #include "she/system.h" +#include #include #include #include @@ -48,8 +49,14 @@ namespace { // Aseprite entry point. (Called from she library.) int app_main(int argc, char* argv[]) { + // Initialize the locale. Aseprite isn't ready to handle numeric + // fields with other locales (e.g. we expect strings like "10.32" be + // used in std::strtod(), not something like "10,32"). + std::setlocale(LC_ALL, "en-US"); + ASSERT(std::strtod("10.32", nullptr) == 10.32); + // Initialize the random seed. - std::srand(static_cast(std::time(NULL))); + std::srand(static_cast(std::time(nullptr))); #ifdef _WIN32 ::CoInitialize(NULL);