1
- // ////////////////////////////////////////////////////////////////////////////////////////
2
- // File: RTEError.cpp
3
- // ////////////////////////////////////////////////////////////////////////////////////////
4
- // Description: Source file for general error handling functions.
5
- // Project: Retro Terrain Engine
6
- // Author(s): Daniel Tabar
7
-
8
- // http://www.datarealms.com
9
-
10
-
11
- // ////////////////////////////////////////////////////////////////////////////////////////
12
- // Inclusions of header files
13
-
14
1
#include " RTEError.h"
15
-
16
-
17
-
18
- namespace RTE
19
- {
20
-
21
- static BITMAP *g_pScreendumpBuffer = 0 ;
22
-
23
-
24
- // ////////////////////////////////////////////////////////////////////////////////////////
25
- // Global function: DDTAbortFunc
26
- // ////////////////////////////////////////////////////////////////////////////////////////
27
- // Description: Abort on Error function. Will try to dump a screenshot, show an
28
- // abortion message, and then quit the program immediately.
29
- // Arguments: The description of the abortion.
30
- // The source file in which the abortion is made.
31
- // The line where the abortion is made.
32
- // Return value: None.
33
-
34
- extern bool DDTAbortFunc (const char *description,
35
- const char *file,
36
- int line)
37
- {
38
- // Save out the screen bitmap, after making a copy of it, faster sometimes
39
- if (screen) {
40
- if (!g_pScreendumpBuffer)
41
- g_pScreendumpBuffer = create_bitmap (screen->w , screen->h );
42
- blit (screen, g_pScreendumpBuffer, 0 , 0 , 0 , 0 , screen->w , screen->h );
43
- PALETTE palette;
44
- get_palette (palette);
45
- save_bmp (" abortscreen.bmp" , g_pScreendumpBuffer, palette);
46
- }
47
-
48
- // Ditch the video mode so the messagebox appears without problems
49
- if (screen != 0 )
50
- set_gfx_mode (GFX_TEXT, 0 , 0 , 0 , 0 );
51
-
52
- // Set title of the messagebox
53
- set_window_title (" RTE Aborted! (x_x)" );
54
-
55
- // Show messagebox with explanation
56
- // allegro_message("Abortion in file %s, line %i, because:\n\n%s\n\nThe last frame has been dumped to 'abortscreen.bmp'", file, line, description);
57
- // Shortened and less confusing one.. users have no use of knowing which source file and where
58
- #ifdef WIN32
59
- allegro_message (" %s\n\n The last frame has been dumped to 'abortscreen.bmp'\n\n You can copy this message with Ctrl+C" , description);
60
- #else // WIN32
61
- allegro_message (" %s\n\n The last frame has been dumped to 'abortscreen.bmp'" , description);
62
- #endif // WIN32
63
- // True so that the asm_ { int 3 } code is run and the debugger goes there.
64
- // exit(-1);
65
- return true ;
66
- }
67
-
68
-
69
- extern bool DDTAbortFunc (const std::string description,
70
- const char *file,
71
- int line)
72
- {
73
- return DDTAbortFunc (description.c_str (), file, line);
74
- }
75
-
76
-
77
- // ////////////////////////////////////////////////////////////////////////////////////////
78
- // Global function: DDTAssert
79
- // ////////////////////////////////////////////////////////////////////////////////////////
80
- // Description: A souped-up, customized assert function that brings up a nice dialog
81
- // box on assert failure, where the user can choose to: break, ignore
82
- // the particular assertion failure once, or to always ignore.
83
-
84
- bool DDTAssert (bool expression,
85
- const char *description,
86
- const char *file,
87
- int line,
88
- bool &alwaysIgnore)
89
- {
90
- // ASSERT(expression);
91
-
92
- if (!expression) {
93
- /*
94
- int response;
95
- char string[512];
96
- sprintf(string, "What: %s\nWhere: %s - Line %i", description, file, line);
97
- response = MessageBox(0,
98
- string,
99
- "Assertion Failure!",
100
- MB_ABORTRETRYIGNORE | MB_ICONSTOP | MB_SETFOREGROUND | MB_TOPMOST);
101
- if (response == IDABORT)
102
- return true;
103
- if (response == IDRETRY)
104
- return false;
105
- if (response == IDIGNORE) {
106
- alwaysIgnore = true;
107
- return false;
108
- }
109
- */
110
- // TODO: Make this display a box in the game asking whether to ignore or abort")
111
- // For now, always abort.
112
- char error[512 ];
113
- sprintf (error, " Assertion failed: %s" , description);
114
- DDTAbortFunc (error, __FILE__, __LINE__);
115
-
116
- // True so that the asm_ { int 3 } code is run and the debugger goes there.
117
- return true ;
118
- }
119
-
120
- // Assert didn't fail
121
- return false ;
122
- }
123
-
124
-
125
- extern bool DDTAssert (bool expression,
126
- std::string description,
127
- const char *file,
128
- int line,
129
- bool &alwaysIgnore)
130
- {
131
- return DDTAssert (expression, description.c_str (), file, line, alwaysIgnore);
132
- }
133
-
134
- } // namespace RTE
2
+ // #include "Constants.h"
3
+
4
+ namespace RTE {
5
+
6
+ // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
+
8
+ extern void ShowMessageBox (std::string message) { allegro_message (message.c_str ()); }
9
+
10
+ // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11
+
12
+ extern bool RTEAbortFunc (const char *description, const char *file, int line) {
13
+ // Save out the screen bitmap, after making a copy of it, faster sometimes
14
+ if (screen) {
15
+ BITMAP *abortScreenBuffer = create_bitmap (screen->w , screen->h );
16
+ blit (screen, abortScreenBuffer, 0 , 0 , 0 , 0 , screen->w , screen->h );
17
+ PALETTE palette;
18
+ get_palette (palette);
19
+ save_bmp (" abortscreen.bmp" , abortScreenBuffer, palette);
20
+ destroy_bitmap (abortScreenBuffer);
21
+ }
22
+ // Ditch the video mode so the message box appears without problems
23
+ if (screen != 0 ) { set_gfx_mode (GFX_TEXT, 0 , 0 , 0 , 0 ); }
24
+ // Set title of the messagebox
25
+ set_window_title (" RTE Aborted! (x_x)" );
26
+
27
+ char message[512 ];
28
+
29
+ #if defined DEBUG_BUILD || defined MIN_DEBUG_BUILD
30
+ // Show message box with explanation
31
+ std::snprintf (message, sizeof (message), " Runtime Error in file %s, line %i, because:\n\n %s\n\n The last frame has been dumped to 'abortscreen.bmp'" , file, line, description);
32
+ allegro_message (message);
33
+ #else
34
+ // Shortened and less confusing one. users have no use of knowing which source file and where.
35
+ std::snprintf (message, sizeof (message), " %s\n\n The last frame has been dumped to 'abortscreen.bmp'" , description);
36
+ allegro_message (message);
37
+ #endif
38
+ // True so that the debugbreak code is run and the debugger goes there.
39
+ return true ;
40
+ }
41
+
42
+ // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
43
+
44
+ extern bool RTEAbortFunc (const std::string description, const char *file, int line) {
45
+ return RTEAbortFunc (description.c_str (), file, line);
46
+ }
47
+
48
+ // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
49
+
50
+ bool RTEAssertFunc (bool expression, const char *description, const char *file, int line, bool &alwaysIgnore) {
51
+ if (!expression) {
52
+ // TODO: Make this display a box in the game asking whether to ignore or abort. For now, always abort.
53
+ RTEAbortFunc (description, __FILE__, __LINE__);
54
+
55
+ // True so that the debugbreak code is run and the debugger goes there.
56
+ return true ;
57
+ }
58
+ return false ;
59
+ }
60
+
61
+ // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
62
+
63
+ extern bool RTEAssertFunc (bool expression, std::string description, const char *file, int line, bool &alwaysIgnore) {
64
+ return RTEAssertFunc (expression, description.c_str (), file, line, alwaysIgnore);
65
+ }
66
+ }
0 commit comments