FUtils/FUAssert.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2005-2006 Feeling Software Inc.
00003     MIT License: http://www.opensource.org/licenses/mit-license.php
00004 */
00005 
00011 #ifndef _FU_ASSERT_H_
00012 #define _FU_ASSERT_H_
00013 
00020 #ifdef _DEBUG
00021 #ifdef WIN32
00022 #define __DEBUGGER_BREAK \
00023     static bool ignoreAssert = false; \
00024     if (!ignoreAssert) { \
00025         fchar message[1024]; \
00026         fsnprintf(message, 1024, FC("[%s@%u] Assertion failed.\nAbort: Enter debugger.\nRetry: Continue execution.\nIgnore: Do not assert at this line for the duration of the application."), FC(__FILE__), __LINE__); \
00027         message[1023] = 0; \
00028         int32 buttonPressed = MessageBox(NULL, message, FC("Assertion failed."), MB_ABORTRETRYIGNORE | MB_ICONWARNING); \
00029         if (buttonPressed == IDABORT) { \
00030             __asm int 3 \
00031         } else if (buttonPressed == IDRETRY) {} \
00032         else if (buttonPressed == IDIGNORE) { ignoreAssert = true; } }
00033 
00034 #else
00035 
00036 // On non-Windows platforms: force a crash?
00037 #define __DEBUGGER_BREAK { \
00038     uint32* __p = NULL; \
00039     uint32 __v = *__p; \
00040     *__p = 0xD1ED0D1E; \
00041     __v = __v + 1; }
00042 
00043 #endif // WIN32
00044 #else
00045 
00051 #define __DEBUGGER_BREAK
00052 
00053 #endif // _DEBUG
00054 
00057 #define FUFail(command) { __DEBUGGER_BREAK; command; }
00058 
00064 #define FUAssert(condition, fall_back) { if (!(condition)) { __DEBUGGER_BREAK; fall_back; } }
00065 
00066 #ifdef _DEBUG
00067 #ifdef WIN32
00068 
00069 #define FUCheckMemory(fallback) FUAssert(_CrtCheckMemory(), fallback);
00070 
00071 #else // WIN32
00072 
00073 // I don't know if there is a Linux equivalent.
00074 #define FUCheckMemory(fallback)
00075 
00076 #endif // WIN32
00077 #else // _DEBUG
00078 
00082 #define FUCheckMemory(fallback)
00083 
00084 #endif
00085 
00086 #endif // _FU_ASSERT_H_

Generated on Fri May 12 16:44:39 2006 for FCollada by  doxygen 1.4.6-NO