Skip to content

Commit e43291a

Browse files
committed
Replace Get<float> by Get<double> in property parsing
With latest version of Boost (1.88), `Get<float>` raises "RuntimeError: bad lexical cast: source type value could not be interpreted as target" exception for floating point values that don't exactly fit `float` precision. Such values can be very innocent-looking: for instance, 39.5978 cannot be stored as is in a float, but will be stored as 39.597801, what will make Boost raise, and give the impression the problem is random. To fix it, the only solution was to parse floating point values as double and then narrow it to float.
1 parent 6b23181 commit e43291a

40 files changed

+665
-656
lines changed

include/luxrays/core/epsilon_types.cl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@
2222
#define DEFAULT_EPSILON_MAX 1e-1f
2323
#define DEFAULT_EPSILON_STATIC 1e-5f
2424

25+
#define DEFAULT_EPSILON_MIN_DBL 1e-5
26+
#define DEFAULT_EPSILON_MAX_DBL 1e-1
27+
#define DEFAULT_EPSILON_STATIC_DBL 1e-5
28+
2529
// An epsilon that can be used as threshold for cos(theta). For instance:
2630
// if (Dot(N, LightDir) < DEFAULT_COS_EPSILON_STATIC) return Spectrum();
2731
#define DEFAULT_COS_EPSILON_STATIC 1e-4f
32+
#define DEFAULT_COS_EPSILON_STATIC_DBL 1e-4
2833

2934
// This is about 1e-5f for values near 1.f
3035
#define DEFAULT_EPSILON_DISTANCE_FROM_VALUE 0x80u

include/luxrays/utils/utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ int isinf(T a) { return std::isinf(a); }
8989
#define INFINITY (std::numeric_limits<float>::infinity())
9090
#endif
9191

92+
#ifndef INFINITY_DBL
93+
#define INFINITY_DBL (std::numeric_limits<double>::infinity())
94+
#endif
95+
9296
#ifndef INV_PI
9397
#define INV_PI 0.31830988618379067154f
9498
#endif

src/luxcore/luxparser/luxparse.cpp

Lines changed: 132 additions & 132 deletions
Large diffs are not rendered by default.

src/luxcore/luxparser/luxparse.y

Lines changed: 132 additions & 132 deletions
Large diffs are not rendered by default.

src/luxrays/accelerators/bvhaccel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ BVHParams BVHAccel::ToBVHParams(const Properties &props) {
5353
const int costSamples = props.Get(Property("accelerator.bvh.costsamples")(0)).Get<int>();
5454
const int isectCost = props.Get(Property("accelerator.bvh.isectcost")(80)).Get<int>();
5555
const int travCost = props.Get(Property("accelerator.bvh.travcost")(10)).Get<int>();
56-
const float emptyBonus = props.Get(Property("accelerator.bvh.emptybonus")(.5)).Get<float>();
56+
const float emptyBonus = props.Get(Property("accelerator.bvh.emptybonus")(.5)).Get<double>();
5757

5858
BVHParams params;
5959
// Make sure treeType is 2, 4 or 8

src/luxrays/utils/properties.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ template<> float PropertyValue::Get<float>() const {
282282
case BLOB_VAL:
283283
throw std::runtime_error("A Blob property can not be converted to other types");
284284
default:
285-
throw std::runtime_error("Unknown type in PropertyValue::Get<float>(): " + ToString(dataType));
285+
throw std::runtime_error("Unknown type in PropertyValue::Get<double>(): " + ToString(dataType));
286286
}
287287
}
288288

@@ -575,41 +575,41 @@ template<> const Blob &Property::Get<const Blob &>() const {
575575
template<> UV Property::Get<UV>() const {
576576
if (values.size() != 2)
577577
throw runtime_error("Wrong number of values in property: " + name);
578-
return UV(Get<float>(0), Get<float>(1));
578+
return UV(Get<double>(0), Get<double>(1));
579579
}
580580

581581
template<> Vector Property::Get<Vector>() const {
582582
if (values.size() != 3)
583583
throw runtime_error("Wrong number of values in property: " + name);
584-
return Vector(Get<float>(0), Get<float>(1), Get<float>(2));
584+
return Vector(Get<double>(0), Get<double>(1), Get<double>(2));
585585
}
586586

587587
template<> Normal Property::Get<Normal>() const {
588588
if (values.size() != 3)
589589
throw runtime_error("Wrong number of values in property: " + name);
590-
return Normal(Get<float>(0), Get<float>(1), Get<float>(2));
590+
return Normal(Get<double>(0), Get<double>(1), Get<double>(2));
591591
}
592592

593593
template<> Point Property::Get<Point>() const {
594594
if (values.size() != 3)
595595
throw runtime_error("Wrong number of values in property: " + name);
596-
return Point(Get<float>(0), Get<float>(1), Get<float>(2));
596+
return Point(Get<double>(0), Get<double>(1), Get<double>(2));
597597
}
598598

599599
template<> Spectrum Property::Get<Spectrum>() const {
600600
if (values.size() != 3)
601601
throw runtime_error("Wrong number of values in property: " + name);
602-
return Spectrum(Get<float>(0), Get<float>(1), Get<float>(2));
602+
return Spectrum(Get<double>(0), Get<double>(1), Get<double>(2));
603603
}
604604

605605
template<> Matrix4x4 Property::Get<Matrix4x4>() const {
606606
if (values.size() != 16)
607607
throw runtime_error("Wrong number of values in property: " + name);
608608
return Matrix4x4(
609-
Get<float>(0), Get<float>(4), Get<float>(8), Get<float>(12),
610-
Get<float>(1), Get<float>(5), Get<float>(9), Get<float>(13),
611-
Get<float>(2), Get<float>(6), Get<float>(10), Get<float>(14),
612-
Get<float>(3), Get<float>(7), Get<float>(11), Get<float>(15));
609+
Get<double>(0), Get<double>(4), Get<double>(8), Get<double>(12),
610+
Get<double>(1), Get<double>(5), Get<double>(9), Get<double>(13),
611+
Get<double>(2), Get<double>(6), Get<double>(10), Get<double>(14),
612+
Get<double>(3), Get<double>(7), Get<double>(11), Get<double>(15));
613613
}
614614

615615
//------------------------------------------------------------------------------

src/slg/core/colorspace.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ void ColorSpaceConfig::FromProperties(const Properties &props, const string &pre
8181
case ColorSpaceConfig::LUXCORE_COLORSPACE: {
8282
colorSpaceCfg.colorSpaceType = LUXCORE_COLORSPACE;
8383
// For compatibility with the past
84-
const float oldGamma = props.Get(Property(prefix + ".gamma")(defaultCfg.luxcore.gamma)).Get<float>();
85-
colorSpaceCfg.luxcore.gamma = props.Get(Property(prefix + ".colorspace.gamma")(oldGamma)).Get<float>();
84+
const float oldGamma = props.Get(Property(prefix + ".gamma")(defaultCfg.luxcore.gamma)).Get<double>();
85+
colorSpaceCfg.luxcore.gamma = props.Get(Property(prefix + ".colorspace.gamma")(oldGamma)).Get<double>();
8686
break;
8787
}
8888
case ColorSpaceConfig::OPENCOLORIO_COLORSPACE: {

src/slg/engines/bakecpu/bakecpu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ BakeCPURenderEngine::BakeCPURenderEngine(const RenderConfig *rcfg) :
5151
skipExistingMapFiles = cfg.Get(Property("bake.skipexistingmapfiles")(false)).Get<bool>();
5252

5353
marginPixels = Max(cfg.Get(Property("bake.margin")(0u)).Get<u_int>(), 0u);
54-
marginSamplesThreshold = Max(cfg.Get(Property("bake.marginsamplesthreshold")(0.f)).Get<float>(), 0.f);
54+
marginSamplesThreshold = Max(cfg.Get(Property("bake.marginsamplesthreshold")(0.0)).Get<double>(), 0.0);
5555

5656
// Read the list of bake maps to render
5757
vector<string> mapKeys = cfg.GetAllUniqueSubNames("bake.maps");

src/slg/engines/bidircpu/bidircpu.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,18 @@ void BiDirCPURenderEngine::StartLockLess() {
6767
maxLightPathDepth = (u_int)Max(1, cfg.Get(GetDefaultProps().Get("light.maxdepth")).Get<int>());
6868

6969
rrDepth = (u_int)Max(1, cfg.Get(GetDefaultProps().Get("path.russianroulette.depth")).Get<int>());
70-
rrImportanceCap = Clamp(cfg.Get(GetDefaultProps().Get("path.russianroulette.cap")).Get<float>(), 0.f, 1.f);
70+
rrImportanceCap = Clamp(cfg.Get(GetDefaultProps().Get("path.russianroulette.cap")).Get<double>(), 0.0, 1.0);
7171

7272
// Clamping settings
7373
// clamping.radiance.maxvalue is the old radiance clamping, now converted in variance clamping
74-
sqrtVarianceClampMaxValue = cfg.Get(Property("path.clamping.radiance.maxvalue")(0.f)).Get<float>();
74+
sqrtVarianceClampMaxValue = cfg.Get(Property("path.clamping.radiance.maxvalue")(0.0)).Get<double>();
7575
if (cfg.IsDefined("path.clamping.variance.maxvalue"))
76-
sqrtVarianceClampMaxValue = cfg.Get(GetDefaultProps().Get("path.clamping.variance.maxvalue")).Get<float>();
76+
sqrtVarianceClampMaxValue = cfg.Get(GetDefaultProps().Get("path.clamping.variance.maxvalue")).Get<double>();
7777
sqrtVarianceClampMaxValue = Max(0.f, sqrtVarianceClampMaxValue);
7878

7979
// Albedo AOV settings
8080
albedoSpecularSetting = String2AlbedoSpecularSetting(cfg.Get(GetDefaultProps().Get("path.albedospecular.type")).Get<string>());
81-
albedoSpecularGlossinessThreshold = Max(cfg.Get(GetDefaultProps().Get("path.albedospecular.glossinessthreshold")).Get<float>(), 0.f);
81+
albedoSpecularGlossinessThreshold = Max(cfg.Get(GetDefaultProps().Get("path.albedospecular.glossinessthreshold")).Get<double>(), 0.0);
8282

8383
//--------------------------------------------------------------------------
8484
// Restore render state if there is one

src/slg/engines/bidirvmcpu/bidirvmcpu.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ void BiDirVMCPURenderEngine::StartLockLess() {
3737
//--------------------------------------------------------------------------
3838

3939
lightPathsCount = Max(1024u, cfg.Get(GetDefaultProps().Get("bidirvm.lightpath.count")).Get<u_int>());
40-
baseRadius = cfg.Get(GetDefaultProps().Get("bidirvm.startradius.scale")).Get<float>() * renderConfig->scene->dataSet->GetBSphere().rad;
41-
radiusAlpha = cfg.Get(GetDefaultProps().Get("bidirvm.alpha")).Get<float>();
40+
baseRadius = cfg.Get(GetDefaultProps().Get("bidirvm.startradius.scale")).Get<double>() * renderConfig->scene->dataSet->GetBSphere().rad;
41+
radiusAlpha = cfg.Get(GetDefaultProps().Get("bidirvm.alpha")).Get<double>();
4242

4343
BiDirCPURenderEngine::StartLockLess();
4444
}

0 commit comments

Comments
 (0)