00001
00002
00003
00004 #include <new.h>
00005 #include <stdlib.h>
00006 #include <stdio.h>
00007 #include <stdarg.h>
00008 #include <windows.h>
00009
00010 #include <OSYS.H>
00011
00012 #include <OVGA.H>
00013 #include <OVGALOCK.H>
00014 #include <ALL.H>
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 static int new_func_handler(size_t);
00027 static void error_quit_game(char *msg);
00028
00029
00030
00031 static char error_flag=0;
00032
00033
00035
00036 err.mem();
00037
00038 return 0;
00039 }
00040
00041
00042
00043
00044 static void error_quit_game(char *msg) {
00045
00046
00047
00048 if( vga_front.dd_buf ) {
00049 VgaFrontLock vgaLock;
00050
00051 ShowCursor(TRUE);
00052 MessageBox(sys.main_hwnd, msg, WIN_TITLE, MB_OK | MB_ICONERROR);
00053 ShowCursor(FALSE);
00054 }
00055 else {
00056 ShowCursor(TRUE);
00057 MessageBox(sys.main_hwnd, msg, WIN_TITLE, MB_OK | MB_ICONERROR);
00058 ShowCursor(FALSE);
00059 }
00060
00061 sys.deinit_directx();
00062 }
00063
00064
00065
00066
00071
00072 _set_new_handler(new_func_handler);
00073
00074 _set_new_mode(1);
00075
00076
00077 extra_handler = NULL;
00078 }
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 void Error::internal(char* errMsg,char* fileName,int lineNum) {
00099 if( error_flag )
00100 return;
00101
00102 error_flag=1;
00103
00104
00105
00106 char strBuf[100];
00107
00108 if( extra_handler )
00109 (*extra_handler)();
00110
00111 if( errMsg )
00112 sprintf(strBuf, "Error : %s\nFile : %s\nLine : %d\n", errMsg,fileName,lineNum );
00113 else
00114 sprintf(strBuf, "Error on File : %s\nLine : %d\n",fileName,lineNum );
00115
00116
00117 OutputDebugString( strBuf );
00118
00119 error_quit_game(strBuf);
00120 exit( -2 );
00121 }
00122
00123
00124
00125
00126
00127
00128
00129
00130 void Error::mem() {
00131 if( error_flag )
00132 return;
00133
00134 error_flag=1;
00135
00136
00137
00138 if( extra_handler )
00139 (*extra_handler)();
00140
00141 char* strBuf = "Insufficient Memory, execution interrupt.";
00142
00143
00144
00145 OutputDebugString( strBuf );
00146 error_quit_game(strBuf);
00147 exit( -2 );
00148 }
00149
00150
00151
00152
00153
00154
00155
00156
00157 void Error::msg( char *format, ... ) {
00158 if( error_flag )
00159 return;
00160
00161 error_flag=1;
00162
00163
00164
00165
00166
00167 char strBuf[100];
00168
00169 va_list argPtr;
00170
00171 va_start( argPtr, format );
00172 vsprintf( strBuf, format, argPtr );
00173
00174 va_end( argPtr );
00175
00176
00177
00178 OutputDebugString( strBuf );
00179 error_quit_game(strBuf);
00180 error_flag = 0;
00181 }
00182
00183
00184
00185
00186
00187
00188
00189
00190 void Error::run( char *format, ... ) {
00191 if( error_flag )
00192 return;
00193
00194 error_flag=1;
00195
00196
00197
00198 if( extra_handler )
00199 (*extra_handler)();
00200
00201
00202
00203 char strBuf[100];
00204
00205 va_list argPtr;
00206
00207 va_start( argPtr, format );
00208 vsprintf( strBuf, format, argPtr );
00209
00210 va_end( argPtr );
00211
00212
00213
00214 OutputDebugString( strBuf );
00215 error_quit_game(strBuf);
00216 exit( -2 );
00217 }
00218
00219