Skip to content

Commit

Permalink
Fix bug pressing warning icon to add palette color when active locale…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
dacap committed Mar 28, 2016
1 parent f2ba51f commit 27b5503
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/allegro/src/x/xkeyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
11 changes: 9 additions & 2 deletions src/main/main.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,6 +22,7 @@
#include "she/scoped_handle.h"
#include "she/system.h"

#include <clocale>
#include <cstdlib>
#include <ctime>
#include <iostream>
Expand All @@ -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<unsigned int>(std::time(NULL)));
std::srand(static_cast<unsigned int>(std::time(nullptr)));

#ifdef _WIN32
::CoInitialize(NULL);
Expand Down

0 comments on commit 27b5503

Please sign in to comment.