]> git.mxchange.org Git - flightgear.git/commitdiff
When attempting to pass a NaN between Nasal and property nodes, catch this.
authorJames Turner <zakalawe@mac.com>
Tue, 19 Oct 2010 23:08:57 +0000 (00:08 +0100)
committerJames Turner <zakalawe@mac.com>
Tue, 28 Dec 2010 11:58:03 +0000 (11:58 +0000)
src/Scripting/NasalSys.cxx
src/Scripting/nasal-props.cxx

index 72c964c04cabdab83b954341fb104620c1990e13..158d852e5bc7ef2d824189fd99ddf6df54489e40 100644 (file)
@@ -186,8 +186,16 @@ static naRef f_getprop(naContext c, naRef me, int argc, naRef* args)
     case props::BOOL:   case props::INT:
     case props::LONG:   case props::FLOAT:
     case props::DOUBLE:
-        return naNum(p->getDoubleValue());
-
+        {
+        double dv = p->getDoubleValue();
+        if (osg::isNaN(dv)) {
+          SG_LOG(SG_GENERAL, SG_ALERT, "Nasal getprop: property " << p->getPath() << " is NaN");
+          naRuntimeError(c, "getprop() would have read NaN");
+        }
+        
+        return naNum(dv);
+        }
+        
     case props::STRING:
     case props::UNSPECIFIED:
         {
@@ -234,6 +242,11 @@ static naRef f_setprop(naContext c, naRef me, int argc, naRef* args)
             naRef n = naNumValue(val);
             if(naIsNil(n))
                 naRuntimeError(c, "setprop() value is not string or number");
+                
+            if (osg::isNaN(n.num)) {
+                naRuntimeError(c, "setprop() passed a NaN");
+            }
+            
             result = props->setDoubleValue(buf, n.num);
         }
     } catch (const string& err) {
index 9f309903a11b7401a2b7992a49926bd53da9ab89..0ea341b08ff2e18283ec46f5ab82ea2d380945a7 100644 (file)
@@ -169,7 +169,16 @@ static naRef f_getValue(naContext c, naRef me, int argc, naRef* args)
     case props::BOOL:   case props::INT:
     case props::LONG:   case props::FLOAT:
     case props::DOUBLE:
-        return naNum((*node)->getDoubleValue());
+    {
+        double dv = (*node)->getDoubleValue();
+        if (osg::isNaN(dv)) {
+          SG_LOG(SG_GENERAL, SG_ALERT, "Nasal getValue: property " << (*node)->getPath() << " is NaN");
+          naRuntimeError(c, "props.getValue() would have read NaN");
+        }
+        
+        return naNum(dv);
+    }
+    
     case props::STRING:
     case props::UNSPECIFIED:
         return NASTR((*node)->getStringValue());
@@ -217,7 +226,13 @@ static naRef f_setValue(naContext c, naRef me, int argc, naRef* args)
         naRef n = naNumValue(val);
         if(naIsNil(n))
             naRuntimeError(c, "props.setValue() with non-number");
-        result = (*node)->setDoubleValue(naNumValue(val).num);
+            
+        double d = naNumValue(val).num;
+        if (osg::isNaN(d)) {
+          naRuntimeError(c, "props.setValue() passed a NaN");
+        }
+        
+        result = (*node)->setDoubleValue(d);
     }
     return naNum(result);
 }
@@ -250,8 +265,13 @@ static naRef f_setDoubleValue(naContext c, naRef me, int argc, naRef* args)
 {
     NODEARG();
     naRef r = naNumValue(naVec_get(argv, 0));
-    if(naIsNil(r))
+    if (naIsNil(r))
         naRuntimeError(c, "props.setDoubleValue() with non-number");
+        
+    if (osg::isNaN(r.num)) {
+      naRuntimeError(c, "props.setDoubleValue() passed a NaN");
+    }
+        
     return naNum((*node)->setDoubleValue(r.num));
 }