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.
This commit is contained in:
parent
4daaaa373c
commit
57800b934e
|
@ -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 <stambaughw@gmail.com>
|
||||
* Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
|
@ -57,9 +57,26 @@ using KIGFX::COLOR4D;
|
|||
EDA_UNITS_T g_UserUnit;
|
||||
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<unsigned int> 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
|
||||
|
@ -67,6 +84,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" );
|
||||
}
|
||||
|
@ -80,6 +101,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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue