From: black Date: Wed, 26 Jul 2006 10:35:38 +0000 (+0000) Subject: 'Catch' divisions by zero in the VM: X-Git-Tag: xonotic-v0.1.0preview~3850 X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=commitdiff_plain;h=da58bedc8a3512a9a4d4272c9ce89b7dd6fe4324 'Catch' divisions by zero in the VM: 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 --- diff --git a/prvm_execprogram.h b/prvm_execprogram.h index b9504c84..78d859e0 100644 --- a/prvm_execprogram.h +++ b/prvm_execprogram.h @@ -47,7 +47,17 @@ 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;