From 4b44cbe6958309581e806fd9eb0e48c17f21187a Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sat, 27 Oct 2018 19:53:52 +0200 Subject: [PATCH] Kicad, Windows specific: disable a overzealous wxWidgets assert when reading a file. When reading (and writing) a file, we must switch the current locale to "C" for LC_NUMERIC. Unfortunately, on Windows, a wxWidgets assert was shown when reading some items (bitmaps images). This wxWidgets assert (related to decimal separator) is overzealous and is now hidden only when reading/writing files. --- common/common.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/common/common.cpp b/common/common.cpp index 5bcb58986c..9d5bca535e 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2014-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2014-2018 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008 Wayne Stambaugh * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors. * @@ -56,9 +56,26 @@ using KIGFX::COLOR4D; COLOR4D g_GhostColor; +#ifdef _WIN32 +// a wxAssertHandler_t function to filter wxWidgets alert messages when reading/writing a file +// when switching the locale to LC_NUMERIC, "C" +// It is used in class LOCALE_IO to hide a useless (in kicad) wxWidgets alert message +void KiAssertFilter( const wxString &file, int line, + const wxString &func, const wxString &cond, + const wxString &msg) +{ + if( !msg.Contains( "Decimal separator mismatch" ) ) + wxTheApp->OnAssertFailure( file, line, func, cond, msg ); +} +#endif std::atomic LOCALE_IO::m_c_count(0); +// Note on Windows, setlocale( LC_NUMERIC, "C" ) works fine to read/write +// files with floating point numbers, but generates a overzealous wx alert +// in some cases (reading a bitmap for instance) +// So we disable alerts during the time a file is read or written + LOCALE_IO::LOCALE_IO() { // use thread safe, atomic operation @@ -66,6 +83,10 @@ LOCALE_IO::LOCALE_IO() { // Store the user locale name, to restore this locale later, in dtor m_user_locale = setlocale( LC_NUMERIC, nullptr ); +#ifdef _WIN32 + // Disable wxWidgets alerts + wxSetAssertHandler( KiAssertFilter ); +#endif // Switch the locale to C locale, to read/write files with fp numbers setlocale( LC_NUMERIC, "C" ); } @@ -79,6 +100,10 @@ LOCALE_IO::~LOCALE_IO() { // revert to the user locale setlocale( LC_NUMERIC, m_user_locale.c_str() ); +#ifdef _WIN32 + // Enaable wxWidgets alerts + wxSetDefaultAssertHandler(); +#endif } }