-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsseErrorHandler.cpp
284 lines (247 loc) · 8.16 KB
/
sseErrorHandler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
//========================================================
// Scaled Simulator Engine
//
// Author: Jason Huntley
//
// Description: Error Exception Handling
//
// Notes:
//
// Y+
// |
// |__ X+
// /
// Z+
//
// License:
//
// Licensed under the Apache License, Version 2.0
// (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of
// the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in
// writing, software distributed under the License is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing
// permissions and limitations under the License.
//
//=========================================================
#include "sseErrorHandler.hpp"
#include "sseLog.h"
#include <SDL2/SDL_opengl.h>
sseErrorHandler::sseErrorHandler()
{
}
// ===================================================================
// _ThrowIfNull [public]
// ===================================================================
// Throw exception if the given pointer is NULL.
void sseErrorHandler::_ThrowIfNull(void *ptr)
{
if (ptr == NULL || ptr == (void *)DEBUG_NULL) {
sseLog *log=sseLog::Instance();
log->Error("Null Pointer Encountered!");
throw sseErrorHandler (sseErrorCodes::ERROR_NULLPOINTER);
}
}
void sseErrorHandler::_ThrowIfSDLInitFailed(int iError)
{
if( iError < 0 )
{
sseLog *log=sseLog::Instance();
log->Error("Failed initializing SDL Video: %s", SDL_GetError());
cerr << "Failed initializing SDL Video : " << SDL_GetError() << endl;
throw sseErrorHandler (sseErrorCodes::ERROR_NULLPOINTER);
}
}
void sseErrorHandler::_ThrowIfSDLQueryFailed(SDL_RendererInfo *pVidInfo)
{
if (pVidInfo == NULL || pVidInfo == (void *)DEBUG_NULL)
{
sseLog *log=sseLog::Instance();
log->Error("Failed quering SDL Video hardware: %s", SDL_GetError());
cerr << "Failed quering SDL Video hardware: " << SDL_GetError() << endl;
throw sseErrorHandler (sseErrorCodes::ERROR_SDL_QUERY);
}
}
void sseErrorHandler::_ThrowIfSDLWindowFail(SDL_Surface *pWindow)
{
if (pWindow == NULL || pWindow == (void *)DEBUG_NULL)
{
sseLog *log=sseLog::Instance();
log->Error("Failed to create window: %s", SDL_GetError());
cerr << "Failed to create window: " << SDL_GetError() << endl;
throw sseErrorHandler (sseErrorCodes::ERROR_SDL_WINDOW);
}
}
void sseErrorHandler::_ThrowIfSDLContextFail(SDL_GLContext *pContext)
{
if (pContext == NULL || pContext == (void *)DEBUG_NULL)
{
sseLog *log=sseLog::Instance();
log->Error("Failed to create context: %s", SDL_GetError());
cerr << "Failed to create context: " << SDL_GetError() << endl;
throw sseErrorHandler (sseErrorCodes::ERROR_SDL_CONTEXT);
}
}
void sseErrorHandler::_ThrowIfSDLRendererFail(SDL_Renderer *pContext)
{
if (pContext == NULL || pContext == (void *)DEBUG_NULL)
{
sseLog *log=sseLog::Instance();
log->Error("Failed to create renderer: %s", SDL_GetError());
cerr << "Failed to create renderer: " << SDL_GetError() << endl;
throw sseErrorHandler (sseErrorCodes::ERROR_SDL_RENDER);
}
}
void sseErrorHandler::_ThrowIfSDLFullScreenSwitch(int iError)
{
if(iError == 0)
{
sseLog *log=sseLog::Instance();
log->Error("Failed to Toggle Fullscreen mode: %s", SDL_GetError());
cerr << "Failed to Toggle Fullscreen mode: " << SDL_GetError() << endl;
throw sseErrorHandler (sseErrorCodes::ERROR_SDL_FULLSCREEN);
}
}
void sseErrorHandler::_ThrowIfSDLUpdateFail(int iError)
{
if(iError != 0)
{
sseLog *log=sseLog::Instance();
log->Error("Failed to swap the buffers: %s", SDL_GetError());
cerr << "Failed to swap the buffers: " << SDL_GetError() << endl;
throw sseErrorHandler (sseErrorCodes::ERROR_SDL_FULLSCREEN);
}
}
void sseErrorHandler::_LogIfSDLCursorFail(int iSDLCALL)
{
if ( iSDLCALL != SDL_DISABLE ) {
sseLog *log=sseLog::Instance();
log->Error("Cursor Fail: %s", SDL_GetError());
cerr << SDL_GetError() << endl;
}
}
void sseErrorHandler::_ThrowIfSDLTextureLoadError()
{
GLenum gl_error=glGetError();
if ( gl_error != GL_NO_ERROR ) {
/* If this failed, the text may exceed texture size limits */
cout << gluErrorString(gl_error) << endl;
printf("Warning: Couldn't create texture: 0x%x\n", gl_error);
sseLog *log=sseLog::Instance();
log->Error("Warning: Couldn't create texture: 0x%x\n", gl_error);
throw sseErrorHandler (sseErrorCodes::ERROR_SDL_TEXTURE_LOAD);
}
}
void sseErrorHandler::_ThrowIfEnableKeyRepFail(int iCall)
{
if (iCall)
throw sseErrorHandler (sseErrorCodes::ERROR_SDL_ENABLE_KEY_REPEAT);
}
void sseErrorHandler::_ThrowIfDisplayFail(sseDisplayManager *pCDisp)
{
if (pCDisp == NULL || pCDisp == (void *)DEBUG_NULL)
throw sseErrorHandler (sseErrorCodes::ERROR_DISPLAY_INIT);
}
void sseErrorHandler::_ThrowIfMatrixError(bool bTest)
{
if (bTest) {
sseLog *log=sseLog::Instance();
log->Error("Matrix Math Error!");
throw sseErrorHandler (sseErrorCodes::ERROR_MATRIX_SIZE);
}
}
void sseErrorHandler::_ThrowIfMatrixSizeError(int rowSize, int colSize)
{
if ((rowSize<=0) || (colSize<=0)) {
sseLog *log=sseLog::Instance();
log->Error("Matrix Size Error!");
throw sseErrorHandler (sseErrorCodes::ERROR_MATRIX_INVALID_SIZE);
}
}
void sseErrorHandler::_ThrowIfVectorError(bool bTest)
{
if (bTest) {
sseLog *log=sseLog::Instance();
log->Error("Vector Error!");
throw sseErrorHandler (sseErrorCodes::ERROR_VECTOR);
}
}
void sseErrorHandler::_ThrowIfUnitVectorError(bool bTest)
{
if (bTest) {
sseLog *log=sseLog::Instance();
log->Error("Unit Vector Error!");
throw sseErrorHandler (sseErrorCodes::ERROR_UNIT_VECTOR);
}
}
void sseErrorHandler::_ThrowIfFontError(int iError)
{
if (iError<0)
throw sseErrorHandler (sseErrorCodes::ERROR_FONT_INIT);
}
void sseErrorHandler::_ThrowIfFontLoadError(TTF_Font *font)
{
if (font == NULL)
throw sseErrorHandler (sseErrorCodes::ERROR_FONT_LOAD);
}
void sseErrorHandler::_ThrowIfFontRenderError(SDL_Surface *text)
{
if (text == NULL)
throw sseErrorHandler (sseErrorCodes::ERROR_FONT_RENDER);
}
void sseErrorHandler::_ThrowIfAC3DInitError(void *ptr, char *szFile)
{
if(ptr == NULL)
{
sseLog *log=sseLog::Instance();
log->Error("Failed to load AC3D: %s.", szFile);
cerr << "Failed to load AC3D: " << szFile << endl;
throw sseErrorHandler (sseErrorCodes::ERROR_AC3D_INIT);
}
}
void sseErrorHandler::_ThrowIfAC3DDispError(int ac3dReturn, char *szFile)
{
if((ac3dReturn == GL_INVALID_VALUE) || (ac3dReturn == GL_INVALID_OPERATION))
{
sseLog *log=sseLog::Instance();
log->Error("Failed to load AC3D: %s.", szFile);
cerr << "Failed to load AC3D: " << szFile << endl;
throw sseErrorHandler (sseErrorCodes::ERROR_AC3D_DISP_RENDER);
}
}
void sseErrorHandler::_ThrowIfOGLRendererError()
{
GLenum gl_error=glGetError();
if ( gl_error != GL_NO_ERROR ) {
/* If this failed, the text may exceed texture size limits */
cout << gluErrorString(gl_error) << endl;
printf("Error: sseGrafxRenderer failed: 0x%x\n", gl_error);
sseLog *log=sseLog::Instance();
log->Error("Error: sseGrafxRenderer failed: 0x%x\n", gl_error);
throw sseErrorHandler (sseErrorCodes::ERROR_OGL_RENDERER_FAILED);
}
}
void sseErrorHandler::_ThrowIfUnitTestFail(bool bTest, const char *szTestName)
{
if (bTest) {
cerr << "Failed to Run Unit Test: " << szTestName << "!" << endl;
sseLog *log=sseLog::Instance();
log->Error("Failed to Run Unit Test: %s!", szTestName);
throw sseErrorHandler (sseErrorCodes::ERROR_UNIT_TEST_FAILED);
}
GLenum gl_error=glGetError();
if ( gl_error != GL_NO_ERROR ) {
/* If this failed, the text may exceed texture size limits */
cout << gluErrorString(gl_error) << endl;
printf("Error: OGL Unit Test Failed: 0x%x\n", gl_error);
sseLog *log=sseLog::Instance();
log->Error("Error: OGL Unit Test Failed: 0x%x\n", gl_error);
throw sseErrorHandler (sseErrorCodes::ERROR_OGL_RENDERER_FAILED);
}
}