@@ -116,39 +116,41 @@ size_t xrDebug::BuildStackTrace(EXCEPTION_POINTERS* exPtrs, char *buffer, size_t
116116 return frameCount;
117117}
118118
119- void xrDebug::GatherInfo (const char *expression , const char *description , const char *arg0, const char *arg1 ,
120- const char *file, int line, const char *function, char *assertionInfo )
119+ void xrDebug::GatherInfo (char *assertionInfo , const ErrorLocation &loc , const char *expr ,
120+ const char *desc, const char *arg1, const char *arg2 )
121121{
122122 char *buffer = assertionInfo;
123- bool extendedDesc = description && strchr (description, ' \n ' );
123+ if (!expr)
124+ expr = " <no expression>" ;
125+ bool extendedDesc = desc && strchr (desc, ' \n ' );
124126 char *prefix = " [error] " ;
125127 buffer += sprintf (buffer, " \n FATAL ERROR\n\n " );
126- buffer += sprintf (buffer, " %sExpression : %s\n " , prefix, expression );
127- buffer += sprintf (buffer, " %sFunction : %s\n " , prefix, function );
128- buffer += sprintf (buffer, " %sFile : %s\n " , prefix, file );
129- buffer += sprintf (buffer, " %sLine : %d\n " , prefix, line );
128+ buffer += sprintf (buffer, " %sExpression : %s\n " , prefix, expr );
129+ buffer += sprintf (buffer, " %sFunction : %s\n " , prefix, loc. Function );
130+ buffer += sprintf (buffer, " %sFile : %s\n " , prefix, loc. File );
131+ buffer += sprintf (buffer, " %sLine : %d\n " , prefix, loc. Line );
130132 if (extendedDesc)
131133 {
132- buffer += sprintf (buffer, " \n %s\n " , description );
133- if (arg0 )
134+ buffer += sprintf (buffer, " \n %s\n " , desc );
135+ if (arg1 )
134136 {
135- buffer += sprintf (buffer, " %s\n " , arg0 );
136- if (arg1 )
137- buffer += sprintf (buffer, " %s\n " , arg1 );
137+ buffer += sprintf (buffer, " %s\n " , arg1 );
138+ if (arg2 )
139+ buffer += sprintf (buffer, " %s\n " , arg2 );
138140 }
139141 }
140142 else
141143 {
142- buffer += sprintf (buffer, " %sDescription : %s\n " , prefix, description );
143- if (arg0 )
144+ buffer += sprintf (buffer, " %sDescription : %s\n " , prefix, desc );
145+ if (arg1 )
144146 {
145- if (arg1 )
147+ if (arg2 )
146148 {
147- buffer += sprintf (buffer, " %sArgument 0 : %s\n " , prefix, arg0 );
148- buffer += sprintf (buffer, " %sArgument 1 : %s\n " , prefix, arg1 );
149+ buffer += sprintf (buffer, " %sArgument 0 : %s\n " , prefix, arg1 );
150+ buffer += sprintf (buffer, " %sArgument 1 : %s\n " , prefix, arg2 );
149151 }
150152 else
151- buffer += sprintf (buffer, " %sArguments : %s\n " , prefix, arg0 );
153+ buffer += sprintf (buffer, " %sArguments : %s\n " , prefix, arg1 );
152154 }
153155 }
154156 buffer += sprintf (buffer, " \n " );
@@ -183,15 +185,23 @@ void xrDebug::GatherInfo(const char *expression, const char *description, const
183185 os_clipboard::copy_to_clipboard (assertionInfo);
184186}
185187
186- void xrDebug::DoExit (const std::string &message )
188+ void xrDebug::Fatal (const ErrorLocation &loc, const char *format, ... )
187189{
188- FlushLog ();
189- MessageBox (NULL , message.c_str (), " Error" , MB_OK|MB_ICONERROR|MB_SYSTEMMODAL);
190- TerminateProcess (GetCurrentProcess (), 1 );
190+ string1024 desc;
191+ va_list args;
192+ va_start (args, format);
193+ vsnprintf (desc, sizeof (desc), format, args);
194+ va_end (args);
195+ bool ignoreAlways = true ;
196+ Fail (ignoreAlways, loc, nullptr , " fatal error" , desc);
191197}
192198
193- void xrDebug::Backend (const char *expression, const char *description, const char *arg0, const char *arg1,
194- const char *file, int line, const char *function, bool &ignoreAlways)
199+ void xrDebug::Fail (bool &ignoreAlways, const ErrorLocation &loc, const char *expr,
200+ long hresult, const char *arg1, const char *arg2)
201+ { Fail (ignoreAlways, loc, expr, xrDebug::ErrorToString (hresult), arg1, arg2); }
202+
203+ void xrDebug::Fail (bool &ignoreAlways, const ErrorLocation &loc, const char *expr,
204+ const char *desc, const char *arg1, const char *arg2)
195205{
196206#ifdef PROFILE_CRITICAL_SECTIONS
197207 static Lock lock (MUTEX_PROFILE_ID (xrDebug::Backend));
@@ -201,7 +211,7 @@ void xrDebug::Backend(const char *expression, const char *description, const cha
201211 lock.Enter ();
202212 ErrorAfterDialog = true ;
203213 string4096 assertionInfo;
204- GatherInfo (expression, description, arg0, arg1, file, line, function, assertionInfo );
214+ GatherInfo (assertionInfo, loc, expr, desc, arg1, arg2 );
205215#ifdef USE_OWN_ERROR_MESSAGE_WINDOW
206216 strcat (assertionInfo,
207217 " \r\n "
@@ -252,6 +262,17 @@ void xrDebug::Backend(const char *expression, const char *description, const cha
252262 lock.Leave ();
253263}
254264
265+ void xrDebug::Fail (bool &ignoreAlways, const ErrorLocation &loc, const char *expr,
266+ const std::string &desc, const char *arg1, const char *arg2)
267+ { Fail (ignoreAlways, loc, expr, desc.c_str (), arg1, arg2); }
268+
269+ void xrDebug::DoExit (const std::string &message)
270+ {
271+ FlushLog ();
272+ MessageBox (NULL , message.c_str (), " Error" , MB_OK|MB_ICONERROR|MB_SYSTEMMODAL);
273+ TerminateProcess (GetCurrentProcess (), 1 );
274+ }
275+
255276LPCSTR xrDebug::ErrorToString (long code)
256277{
257278 const char *result = nullptr ;
@@ -265,57 +286,6 @@ LPCSTR xrDebug::ErrorToString(long code)
265286 return result;
266287}
267288
268- void xrDebug::Error (long hr, const char *expr, const char *file, int line, const char *function, bool &ignoreAlways)
269- {
270- Backend (expr, ErrorToString (hr), nullptr , nullptr , file, line, function, ignoreAlways);
271- }
272-
273- void xrDebug::Error (long hr, const char *expr, const char *e2 , const char *file, int line, const char *function,
274- bool &ignoreAlways)
275- {
276- Backend (expr, ErrorToString (hr), e2 , 0 , file, line, function, ignoreAlways);
277- }
278-
279- void xrDebug::Fail (const char *e1 , const char *file, int line, const char *function, bool &ignoreAlways)
280- {
281- Backend (e1 , " assertion failed" , 0 , 0 , file, line, function, ignoreAlways);
282- }
283-
284- void xrDebug::Fail (const char *e1 , const std::string &e2 , const char *file, int line, const char *function,
285- bool &ignoreAlways)
286- {
287- Backend (e1 , e2 .c_str (), 0 , 0 , file, line, function, ignoreAlways);
288- }
289-
290- void xrDebug::Fail (const char *e1 , const char *e2 , const char *file, int line, const char *function,
291- bool &ignoreAlways)
292- {
293- Backend (e1 , e2 , 0 , 0 , file, line, function, ignoreAlways);
294- }
295-
296- void xrDebug::Fail (const char *e1 , const char *e2 , const char *e3 , const char *file, int line, const char *function,
297- bool &ignoreAlways)
298- {
299- Backend (e1 , e2 , e3 , 0 , file, line, function, ignoreAlways);
300- }
301-
302- void xrDebug::Fail (const char *e1 , const char *e2 , const char *e3 , const char *e4 , const char *file, int line,
303- const char *function, bool &ignoreAlways)
304- {
305- Backend (e1 , e2 , e3 , e4 , file, line, function, ignoreAlways);
306- }
307-
308- void xrDebug::Fatal (const char *file, int line, const char *function, const char *format, ...)
309- {
310- string1024 buffer;
311- va_list p;
312- va_start (p, format);
313- vsprintf (buffer, format, p);
314- va_end (p);
315- bool ignoreAlways = true ;
316- Backend (nullptr , " fatal error" , buffer, 0 , file, line, function, ignoreAlways);
317- }
318-
319289int out_of_memory_handler (size_t size)
320290{
321291 xrDebug::OutOfMemoryCallbackFunc cb = xrDebug::GetOutOfMemoryCallback ();
@@ -513,8 +483,7 @@ void _terminate()
513483 if (strstr (GetCommandLine (), " -silent_error_mode" ))
514484 exit (-1 );
515485 string4096 assertionInfo;
516- xrDebug::GatherInfo (nullptr , " Unexpected application termination" , nullptr , nullptr ,
517- DEBUG_INFO, assertionInfo);
486+ xrDebug::GatherInfo (assertionInfo, DEBUG_INFO, nullptr , " Unexpected application termination" );
518487 strcat (assertionInfo, " Press OK to abort execution\r\n " );
519488 MessageBox (GetTopWindow (NULL ), assertionInfo, " Fatal Error" , MB_OK|MB_ICONERROR|MB_SYSTEMMODAL);
520489 exit (-1 );
@@ -524,7 +493,7 @@ void _terminate()
524493static void handler_base (const char *reason)
525494{
526495 bool ignoreAlways = false ;
527- xrDebug::Backend ( nullptr , reason , nullptr , nullptr , DEBUG_INFO, ignoreAlways );
496+ xrDebug::Fail (ignoreAlways, DEBUG_INFO , nullptr , reason, nullptr , nullptr );
528497}
529498
530499static void invalid_parameter_handler (const wchar_t *expression, const wchar_t *function,
@@ -550,7 +519,7 @@ static void invalid_parameter_handler(const wchar_t *expression, const wchar_t *
550519 line = __LINE__;
551520 xr_strcpy (mbFile, __FILE__);
552521 }
553- xrDebug::Backend (mbExpression, " invalid parameter " , nullptr , nullptr , mbFile, line, mbFunction, ignoreAlways );
522+ xrDebug::Fail (ignoreAlways, { mbFile, int ( line) , mbFunction}, mbExpression, " invalid parameter " );
554523}
555524
556525static void pure_call_handler ()
0 commit comments