DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

sys_assert.cpp (3299B)


      1 /*
      2 ===========================================================================
      3 
      4 Doom 3 BFG Edition GPL Source Code
      5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 
      6 
      7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").  
      8 
      9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
     10 it under the terms of the GNU General Public License as published by
     11 the Free Software Foundation, either version 3 of the License, or
     12 (at your option) any later version.
     13 
     14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
     15 but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17 GNU General Public License for more details.
     18 
     19 You should have received a copy of the GNU General Public License
     20 along with Doom 3 BFG Edition Source Code.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code.  If not, please request a copy in writing from id Software at the address below.
     23 
     24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
     25 
     26 ===========================================================================
     27 */
     28 #pragma hdrstop
     29 #include "../precompiled.h"
     30 
     31 /*
     32 ================================================================================================
     33 Contains the AssertMacro implementation.
     34 ================================================================================================
     35 */
     36 
     37 idCVar com_assertOutOfDebugger( "com_assertOutOfDebugger", "0", CVAR_BOOL, "by default, do not assert while not running under the debugger" );
     38 
     39 struct skippedAssertion_t {
     40 					skippedAssertion_t() :
     41 						file( NULL ),
     42 						line( -1 ) {
     43 					}
     44 	const char *	file;
     45 	int				line;
     46 };
     47 static idStaticList< skippedAssertion_t,20 > skippedAssertions;
     48 
     49 /*
     50 ========================
     51 AssertFailed
     52 ========================
     53 */
     54 bool AssertFailed( const char * file, int line, const char * expression ) {
     55 	// Set this to true to skip ALL assertions, including ones YOU CAUSE!
     56 	static volatile bool skipAllAssertions = false;
     57 	if ( skipAllAssertions ) {
     58 		return false;
     59 	}
     60 
     61 	// Set this to true to skip ONLY this assertion
     62 	static volatile bool skipThisAssertion = false;
     63 	skipThisAssertion = false;
     64 
     65 	for ( int i = 0; i < skippedAssertions.Num(); i++ ) {
     66 		if ( skippedAssertions[i].file == file && skippedAssertions[i].line == line ) {
     67 			skipThisAssertion = true;
     68 			// Set breakpoint here to re-enable
     69 			if ( !skipThisAssertion ) {
     70 				skippedAssertions.RemoveIndexFast( i );
     71 			}
     72 			return false;
     73 		}
     74 	}
     75 
     76 	idLib::Warning( "ASSERTION FAILED! %s(%d): '%s'", file, line, expression );
     77 
     78 	if ( IsDebuggerPresent() || com_assertOutOfDebugger.GetBool() ) {
     79 			__debugbreak();
     80 	}
     81 
     82 	if ( skipThisAssertion ) {
     83 		skippedAssertion_t * skipped = skippedAssertions.Alloc();
     84 		skipped->file = file;
     85 		skipped->line = line;
     86 	}
     87 
     88 	return true;
     89 }
     90