From da58bedc8a3512a9a4d4272c9ce89b7dd6fe4324 Mon Sep 17 00:00:00 2001
From: black <black@d7cf8633-e32d-0410-b094-e92efae38249>
Date: Wed, 26 Jul 2006 10:35:38 +0000
Subject: [PATCH] '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
---
 prvm_execprogram.h | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

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;
-- 
2.39.5