From 8a85c4ce28baef9800f44709c99b336f8002104c Mon Sep 17 00:00:00 2001 From: Victor Haefner Date: Mon, 1 Mar 2021 20:59:05 +0100 Subject: [PATCH] fixed stringstream to float bug under windows --- .../scene/interfaces/VRScenegraphInterface.cpp | 17 +++++++++++------ src/core/utils/toString.cpp | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/core/scene/interfaces/VRScenegraphInterface.cpp b/src/core/scene/interfaces/VRScenegraphInterface.cpp index d817cf265..b100584f1 100644 --- a/src/core/scene/interfaces/VRScenegraphInterface.cpp +++ b/src/core/scene/interfaces/VRScenegraphInterface.cpp @@ -105,11 +105,12 @@ void parseOSGVec(string& data, V& v) { while (ss >> f) v->addValue(f); } -template +// T2 allows to pass type double because stringstreams may fail to convert scientific notations to float +template void parseOSGVec2(string& data, V& v) { int N = sizeof(U)/sizeof(T); stringstream ss(data); - T f; + T2 f; U u; int i=0; while (ss >> f) { @@ -120,6 +121,10 @@ void parseOSGVec2(string& data, V& v) { v->addValue(u); } } + + if (ss.fail()) { + cout << " parseOSGVec2 failed!" << endl; + } } VRObjectPtr VRScenegraphInterface::getObject(string objID) { @@ -1070,7 +1075,7 @@ void VRScenegraphInterface::handle(string msg) { if (geo && m.size() > 3) { GeoPnt3fPropertyMTRecPtr pos = GeoPnt3fProperty::create(); replace( m[3].begin(), m[3].end(), ',', '.'); - parseOSGVec2(m[3], pos); + parseOSGVec2(m[3], pos); geo->setPositions(pos); //cout << "set geo positions " << geo->getName() << " " << pos->size() << endl; } @@ -1080,9 +1085,9 @@ void VRScenegraphInterface::handle(string msg) { if (geo && m.size() > 3) { GeoVec3fPropertyMTRecPtr norms = GeoVec3fProperty::create(); replace( m[3].begin(), m[3].end(), ',', '.'); - parseOSGVec2(m[3], norms); + parseOSGVec2(m[3], norms); geo->setNormals(norms); - //cout << "set geo normals " << geo->getName() << " " << norms->size() << endl; + //cout << "set geo normals " << geo->getName() << " " << norms->size() << " " << m[3].size() << endl; } } @@ -1090,7 +1095,7 @@ void VRScenegraphInterface::handle(string msg) { if (geo && m.size() > 3) { GeoColor4fPropertyMTRecPtr cols = GeoColor4fProperty::create(); replace( m[3].begin(), m[3].end(), ',', '.'); - parseOSGVec2(m[3], cols); + parseOSGVec2(m[3], cols); geo->setColors(cols); //cout << "set geo colors " << geo->getName() << " " << cols->size() << endl; } diff --git a/src/core/utils/toString.cpp b/src/core/utils/toString.cpp index bf112c7c7..875ef814c 100644 --- a/src/core/utils/toString.cpp +++ b/src/core/utils/toString.cpp @@ -228,7 +228,7 @@ template<> int toValue(stringstream& ss, int& v) { return ssToVal(ss, v); } template<> int toValue(stringstream& ss, unsigned int& v) { return ssToVal(ss, v); } template<> int toValue(stringstream& ss, long& v) { return ssToVal(ss, v); } template<> int toValue(stringstream& ss, unsigned long& v) { return ssToVal(ss, v); } -template<> int toValue(stringstream& ss, float& v) { return ssToVal(ss, v); } +template<> int toValue(stringstream& ss, float& v) { double d; auto r = ssToVal(ss, d); v = d; return r; } // use double because stringstreams may fail to convert scientific notations to float template<> int toValue(stringstream& ss, double& v) { return ssToVal(ss, v); } int toInt (string s) { return toValue(s); }