]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
'Catch' divisions by zero in the VM:
authorblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 26 Jul 2006 10:35:38 +0000 (10:35 +0000)
committerblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 26 Jul 2006 10:35:38 +0000 (10:35 +0000)
print a warning if developer >= 1 and return 0.0 as result of the operation.

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6532 d7cf8633-e32d-0410-b094-e92efae38249

prvm_execprogram.h

index b9504c84e493a06c1c63b8bb9a826cd3d1ff8926..78d859e0a25a4b0b0b35b6a5d9d1ed0e0f937558 100644 (file)
                                OPC->vector[2] = OPB->_float * OPA->vector[2];
                                break;
                        case OP_DIV_F:
-                               OPC->_float = OPA->_float / OPB->_float;
+                               if( OPB->_float != 0.0f )
+                               {
+                                       OPC->_float = OPA->_float / OPB->_float;
+                               } 
+                               else 
+                               {
+                                       if( developer.integer >= 1 ) {
+                                               VM_Warning( "Attempted division by zero in %s\n", PRVM_NAME );
+                                       }
+                                       OPC->_float = 0.0f;
+                               }
                                break;
                        case OP_BITAND:
                                OPC->_float = (int)OPA->_float & (int)OPB->_float;