2222 * *
2323 * Project Name : WWDebug *
2424 * *
25- * $Archive:: /VSS_Sync/ wwdebug/wwdebug.cpp $*
25+ * $Archive:: /Commando/Code/ wwdebug/wwdebug.cpp $*
2626 * *
27- * $Author:: Vss_sync $*
27+ * $Author:: Greg_h $*
2828 * *
29- * $Modtime:: 10/19/00 2:12p $*
29+ * $Modtime:: 1/13/02 1:46p $*
3030 * *
31- * $Revision:: 13 $*
31+ * $Revision:: 16 $*
3232 * *
3333 *---------------------------------------------------------------------------------------------*
3434 * Functions: *
5050#include < stdio.h>
5151#include < assert.h>
5252#include < string.h>
53+ #include < signal.h>
54+ #include " Except.h"
5355
5456
5557static PrintFunc _CurMessageHandler = NULL ;
@@ -93,7 +95,7 @@ int Get_Last_System_Error()
9395 * 2/19/98 GTH : Created. *
9496 *=============================================================================================*/
9597PrintFunc WWDebug_Install_Message_Handler (PrintFunc func)
96- {
98+ {
9799 PrintFunc tmp = _CurMessageHandler;
98100 _CurMessageHandler = func;
99101 return tmp;
@@ -192,13 +194,13 @@ ProfileFunc WWDebug_Install_Profile_Stop_Handler(ProfileFunc func)
192194 * HISTORY: *
193195 * 2/19/98 GTH : Created. *
194196 *=============================================================================================*/
195- # ifdef WWDEBUG
197+
196198void WWDebug_Printf (const char * format,...)
197199{
198200 if (_CurMessageHandler != NULL ) {
199-
201+
200202 va_list va;
201- char buffer[1024 ];
203+ char buffer[4096 ];
202204
203205 va_start (va, format);
204206 vsprintf (buffer, format, va);
@@ -209,7 +211,6 @@ void WWDebug_Printf(const char * format,...)
209211
210212 }
211213}
212- #endif
213214
214215/* **********************************************************************************************
215216 * WWDebug_Printf_Warning -- Internal function for passing messages to installed handler *
@@ -223,13 +224,13 @@ void WWDebug_Printf(const char * format,...)
223224 * HISTORY: *
224225 * 2/19/98 GTH : Created. *
225226 *=============================================================================================*/
226- # ifdef WWDEBUG
227+
227228void WWDebug_Printf_Warning (const char * format,...)
228229{
229230 if (_CurMessageHandler != NULL ) {
230-
231+
231232 va_list va;
232- char buffer[1024 ];
233+ char buffer[4096 ];
233234
234235 va_start (va, format);
235236 vsprintf (buffer, format, va);
@@ -240,7 +241,6 @@ void WWDebug_Printf_Warning(const char * format,...)
240241
241242 }
242243}
243- #endif
244244
245245/* **********************************************************************************************
246246 * WWDebug_Printf_Error -- Internal function for passing messages to installed handler *
@@ -254,13 +254,13 @@ void WWDebug_Printf_Warning(const char * format,...)
254254 * HISTORY: *
255255 * 2/19/98 GTH : Created. *
256256 *=============================================================================================*/
257- # ifdef WWDEBUG
257+
258258void WWDebug_Printf_Error (const char * format,...)
259259{
260260 if (_CurMessageHandler != NULL ) {
261-
261+
262262 va_list va;
263- char buffer[1024 ];
263+ char buffer[4096 ];
264264
265265 va_start (va, format);
266266 vsprintf (buffer, format, va);
@@ -271,7 +271,6 @@ void WWDebug_Printf_Error(const char * format,...)
271271
272272 }
273273}
274- #endif
275274
276275/* **********************************************************************************************
277276 * WWDebug_Assert_Fail -- Internal function for passing assert messages to installed handler *
@@ -289,20 +288,70 @@ void WWDebug_Printf_Error(const char * format,...)
289288void WWDebug_Assert_Fail (const char * expr,const char * file, int line)
290289{
291290 if (_CurAssertHandler != NULL ) {
292-
293- char buffer[1024 ];
291+
292+ char buffer[4096 ];
294293 sprintf (buffer," %s (%d) Assert: %s\n " ,file,line,expr);
295294 _CurAssertHandler (buffer);
296295
297296 } else {
298297
299- assert (0 );
298+ /*
299+ // If the exception handler is try to quit the game then don't show an assert.
300+ */
301+ if (Is_Trying_To_Exit ()) {
302+ ExitProcess (0 );
303+ }
300304
301- }
305+ char assertbuf[4096 ];
306+ sprintf (assertbuf, " Assert failed\n\n . File %s Line %d" , file, line);
307+
308+ int code = MessageBoxA (NULL , assertbuf, " WWDebug_Assert_Fail" , MB_ABORTRETRYIGNORE|MB_ICONHAND|MB_SETFOREGROUND|MB_TASKMODAL);
309+
310+ if (code == IDABORT) {
311+ raise (SIGABRT);
312+ _exit (3 );
313+ }
314+
315+ if (code == IDRETRY) {
316+ WWDEBUG_BREAK
317+ return ;
318+ }
319+ }
302320}
303321#endif
304322
305323
324+
325+
326+ /* **********************************************************************************************
327+ * _assert -- Catch all asserts by overriding lib function *
328+ * *
329+ * *
330+ * *
331+ * INPUT: Assert stuff *
332+ * *
333+ * OUTPUT: Nothing *
334+ * *
335+ * WARNINGS: None *
336+ * *
337+ * HISTORY: *
338+ * 12/11/2001 3:56PM ST : Created *
339+ *=============================================================================================*/
340+ #if 0 //(gth) this is giving me link errors for some reason...
341+
342+ #ifndef W3D_MAX4
343+ #ifdef WWDEBUG
344+ void __cdecl _assert(void *expr, void *filename, unsigned lineno)
345+ {
346+ WWDebug_Assert_Fail((const char*)expr, (const char*)filename, lineno);
347+ }
348+ #endif //WWDEBUG
349+ #endif
350+
351+ #endif
352+
353+
354+
306355/* **********************************************************************************************
307356 * WWDebug_Assert_Fail_Print -- Internal function, passes assert message to handler *
308357 * *
@@ -320,14 +369,14 @@ void WWDebug_Assert_Fail_Print(const char * expr,const char * file, int line,con
320369{
321370 if (_CurAssertHandler != NULL ) {
322371
323- char buffer[1024 ];
372+ char buffer[4096 ];
324373 sprintf (buffer," %s (%d) Assert: %s %s\n " ,file,line,expr, string);
325374 _CurAssertHandler (buffer);
326375
327376 } else {
328377
329378 assert (0 );
330-
379+
331380 }
332381}
333382#endif
@@ -422,7 +471,7 @@ void WWDebug_DBWin32_Message_Handler( const char * str )
422471 if ( !heventDBWIN )
423472 {
424473 // MessageBox(NULL, "DBWIN_BUFFER_READY nonexistent", NULL, MB_OK);
425- return ;
474+ return ;
426475 }
427476
428477 /* get a handle to the data synch object */
@@ -431,11 +480,11 @@ void WWDebug_DBWin32_Message_Handler( const char * str )
431480 {
432481 // MessageBox(NULL, "DBWIN_DATA_READY nonexistent", NULL, MB_OK);
433482 CloseHandle (heventDBWIN);
434- return ;
483+ return ;
435484 }
436-
485+
437486 hSharedFile = CreateFileMapping ((HANDLE)-1 , NULL , PAGE_READWRITE, 0 , 4096 , " DBWIN_BUFFER" );
438- if (!hSharedFile)
487+ if (!hSharedFile)
439488 {
440489 // MessageBox(NULL, "DebugTrace: Unable to create file mapping object DBWIN_BUFFER", "Error", MB_OK);
441490 CloseHandle (heventDBWIN);
@@ -444,7 +493,7 @@ void WWDebug_DBWin32_Message_Handler( const char * str )
444493 }
445494
446495 lpszSharedMem = (LPSTR)MapViewOfFile (hSharedFile, FILE_MAP_WRITE, 0 , 0 , 512 );
447- if (!lpszSharedMem)
496+ if (!lpszSharedMem)
448497 {
449498 // MessageBox(NULL, "DebugTrace: Unable to map shared memory", "Error", MB_OK);
450499 CloseHandle (heventDBWIN);
@@ -470,4 +519,3 @@ void WWDebug_DBWin32_Message_Handler( const char * str )
470519 return ;
471520}
472521#endif // WWDEBUG
473-
0 commit comments