source: NonGTP/FCollada/FUtils/FUAssert.h @ 964

Revision 964, 2.3 KB checked in by igarcia, 18 years ago (diff)
RevLine 
[964]1/*
2        Copyright (C) 2005-2006 Feeling Software Inc.
3        MIT License: http://www.opensource.org/licenses/mit-license.php
4*/
5
6/**
7        @file FUAssert.h
8        This file contains a simple debugging assertion mechanism.
9*/
10
11#ifndef _FU_ASSERT_H_
12#define _FU_ASSERT_H_
13
14/**
15        Breaks into the debugger.
16        In debug builds, this intentionally crashes the application.
17        In release builds, this is an empty function.
18*/
19
20#ifdef _DEBUG
21#ifdef WIN32
22#define __DEBUGGER_BREAK \
23        static bool ignoreAssert = false; \
24        if (!ignoreAssert) { \
25                fchar message[1024]; \
26                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__); \
27                message[1023] = 0; \
28                int32 buttonPressed = MessageBox(NULL, message, FC("Assertion failed."), MB_ABORTRETRYIGNORE | MB_ICONWARNING); \
29                if (buttonPressed == IDABORT) { \
30                        __asm int 3 \
31                } else if (buttonPressed == IDRETRY) {} \
32                else if (buttonPressed == IDIGNORE) { ignoreAssert = true; } }
33
34#else
35
36// On non-Windows platforms: force a crash?
37#define __DEBUGGER_BREAK { \
38        uint32* __p = NULL; \
39        uint32 __v = *__p; \
40        *__p = 0xD1ED0D1E; \
41        __v = __v + 1; }
42
43#endif // WIN32
44#else
45
46/**
47        Breaks into the debugger.
48        In debug builds, this intentionally crashes the application.
49        In release builds, this is an empty function.
50*/
51#define __DEBUGGER_BREAK
52
53#endif // _DEBUG
54
55/** Forces the debugger to break, or take the fall-back.
56        @param command The fall_back command to execute. */
57#define FUFail(command) { __DEBUGGER_BREAK; command; }
58
59/** Asserts that a condition is met.
60        Use this macro, instead of 'if' statements
61        when you are asserting for a programmer's error.
62        @param condition The condition to assert.
63        @param fall_back The command to execute if the condition is not met. */
64#define FUAssert(condition, fall_back) { if (!(condition)) { __DEBUGGER_BREAK; fall_back; } }
65
66#ifdef _DEBUG
67#ifdef WIN32
68
69#define FUCheckMemory(fallback) FUAssert(_CrtCheckMemory(), fallback);
70
71#else // WIN32
72
73// I don't know if there is a Linux equivalent.
74#define FUCheckMemory(fallback)
75
76#endif // WIN32
77#else // _DEBUG
78
79/** Asserts that the memory is intact.
80        This function is only supported on Windows, debug builds right now:
81        it uses the _CrtCheckMemory function and is very expensive. */
82#define FUCheckMemory(fallback)
83
84#endif
85
86#endif // _FU_ASSERT_H_
Note: See TracBrowser for help on using the repository browser.