Skip to content

Commit b0528cf

Browse files
authored
[GEN] Backport WWDebug changes to wwdebug, wwmemlog, wwprofile from Zero Hour (#680)
1 parent 4fe88de commit b0528cf

File tree

10 files changed

+1745
-148
lines changed

10 files changed

+1745
-148
lines changed

Generals/Code/Libraries/Source/WWVegas/WWDebug/wwdebug.cpp

Lines changed: 77 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
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: *
@@ -50,6 +50,8 @@
5050
#include <stdio.h>
5151
#include <assert.h>
5252
#include <string.h>
53+
#include <signal.h>
54+
#include "Except.h"
5355

5456

5557
static PrintFunc _CurMessageHandler = NULL;
@@ -93,7 +95,7 @@ int Get_Last_System_Error()
9395
* 2/19/98 GTH : Created. *
9496
*=============================================================================================*/
9597
PrintFunc 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+
196198
void 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+
227228
void 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+
258258
void 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,...)
289288
void 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-

Generals/Code/Libraries/Source/WWVegas/WWDebug/wwdebug.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
#ifndef WWDEBUG_H
4242
#define WWDEBUG_H
43-
43+
4444
// TheSuperHackers @todo Recover WWDEBUG?
4545
#ifdef WWDEBUG
4646
#include <Utility/intrin_compat.h>
@@ -87,10 +87,10 @@ ProfileFunc WWDebug_Install_Profile_Stop_Handler(ProfileFunc func);
8787
/*
8888
** Users should not call the following three functions directly! Use the macros below instead...
8989
*/
90-
#ifdef WWDEBUG
9190
void WWDebug_Printf(const char * format,...);
9291
void WWDebug_Printf_Warning(const char * format,...);
9392
void WWDebug_Printf_Error(const char * format,...);
93+
#ifdef WWDEBUG
9494
void WWDebug_Assert_Fail(const char * expr,const char * file, int line);
9595
void WWDebug_Assert_Fail_Print(const char * expr,const char * file, int line,const char * string);
9696
bool WWDebug_Check_Trigger(int trigger_num);
@@ -123,6 +123,9 @@ void WWDebug_DBWin32_Message_Handler( const char * message);
123123
// WW3d is compiled at warning level 4, causes DEBUG_ASSERTCRASH to generate
124124
// the 4127 warning (constant conditional expression)
125125
#pragma warning(disable:4127)
126+
#define WWRELEASE_SAY(x) WWDebug_Printf x
127+
#define WWRELEASE_WARNING(x) WWDebug_Printf_Warning x
128+
#define WWRELEASE_ERROR(x) WWDebug_Printf_Error x
126129
/*
127130
** The WWASSERT and WWASSERT_PRINT macros will send messages to your
128131
** assert handler.
@@ -144,7 +147,7 @@ void WWDebug_DBWin32_Message_Handler( const char * message);
144147
** the debugger...
145148
*/
146149
#ifdef WWDEBUG
147-
# define WWDEBUG_BREAK __debugbreak();
150+
#define WWDEBUG_BREAK __debugbreak();
148151
#else
149152
#define WWDEBUG_BREAK
150153
#endif

0 commit comments

Comments
 (0)