mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 20:53:50 +00:00
Revert to lexical_cast<float>, catch out-of-range exceptions
This commit is contained in:
parent
932691d199
commit
e412e1b41c
1 changed files with 10 additions and 2 deletions
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include <components/debug/debuglog.hpp>
|
#include <components/debug/debuglog.hpp>
|
||||||
|
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
namespace Fallback
|
namespace Fallback
|
||||||
{
|
{
|
||||||
Map::Map(const std::map<std::string,std::string>& fallback):mFallbackMap(fallback)
|
Map::Map(const std::map<std::string,std::string>& fallback):mFallbackMap(fallback)
|
||||||
|
@ -24,9 +26,11 @@ namespace Fallback
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return std::stof(fallback);
|
// We have to rely on Boost because std::stof from C++11
|
||||||
|
// uses the current locale for separators which we don't want and often silently ignores parsing errors.
|
||||||
|
return boost::lexical_cast<float>(fallback);
|
||||||
}
|
}
|
||||||
catch (const std::invalid_argument&)
|
catch (boost::bad_lexical_cast&)
|
||||||
{
|
{
|
||||||
Log(Debug::Error) << "Error: '" << fall << "' setting value (" << fallback << ") is not a valid number, using 0 as a fallback";
|
Log(Debug::Error) << "Error: '" << fall << "' setting value (" << fallback << ") is not a valid number, using 0 as a fallback";
|
||||||
}
|
}
|
||||||
|
@ -48,6 +52,10 @@ namespace Fallback
|
||||||
{
|
{
|
||||||
Log(Debug::Error) << "Error: '" << fall << "' setting value (" << fallback << ") is not a valid number, using 0 as a fallback";
|
Log(Debug::Error) << "Error: '" << fall << "' setting value (" << fallback << ") is not a valid number, using 0 as a fallback";
|
||||||
}
|
}
|
||||||
|
catch (const std::out_of_range&)
|
||||||
|
{
|
||||||
|
Log(Debug::Error) << "Error: '" << fall << "' setting value (" << fallback << ") is out of range, using 0 as a fallback";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue