*/
LONG WINAPI lamexp_exception_handler(__in struct _EXCEPTION_POINTERS *ExceptionInfo)
{
- if(GetCurrentThreadId() != g_main_thread_id)
- {
- HANDLE mainThread = OpenThread(THREAD_TERMINATE, FALSE, g_main_thread_id);
- if(mainThread) TerminateThread(mainThread, ULONG_MAX);
- }
-
- FatalAppExit(0, L"Unhandeled exception handler invoked, application will exit!");
- TerminateProcess(GetCurrentProcess(), -1);
+ lamexp_fatal_exit(L"Unhandeled exception handler invoked, application will exit!");
return LONG_MAX;
}
*/
void lamexp_invalid_param_handler(const wchar_t* exp, const wchar_t* fun, const wchar_t* fil, unsigned int, uintptr_t)
{
- if(GetCurrentThreadId() != g_main_thread_id)
- {
- HANDLE mainThread = OpenThread(THREAD_TERMINATE, FALSE, g_main_thread_id);
- if(mainThread) TerminateThread(mainThread, ULONG_MAX);
-
- }
-
- FatalAppExit(0, L"Invalid parameter handler invoked, application will exit!");
- TerminateProcess(GetCurrentProcess(), -1);
+ lamexp_fatal_exit(L"Invalid parameter handler invoked, application will exit!");
}
/*
*/
void lamexp_message_handler(QtMsgType type, const char *msg)
{
- static volatile bool bFatalFlag = false;
static const char *GURU_MEDITATION = "\n\nGURU MEDITATION !!!\n\n";
- if(bFatalFlag || (msg == NULL))
- {
- return; //We are about to terminate, discard any further messages!
- }
+ if(msg == NULL) return;
QMutexLocker lock(&g_lamexp_message_mutex);
{
case QtCriticalMsg:
case QtFatalMsg:
- bFatalFlag = true;
fflush(stdout);
fflush(stderr);
lamexp_console_color(stderr, FOREGROUND_RED | FOREGROUND_INTENSITY);
OutputDebugStringA(temp.toLatin1().constData());
}
- if(bFatalFlag)
+ if((type == QtCriticalMsg) || (type == QtFatalMsg))
{
lock.unlock();
-
- if(GetCurrentThreadId() != g_main_thread_id)
- {
- HANDLE mainThread = OpenThread(THREAD_TERMINATE, FALSE, g_main_thread_id);
- if(mainThread) TerminateThread(mainThread, ULONG_MAX);
- }
-
- MessageBoxW(NULL, QWCHAR(QString::fromUtf8(msg)), L"LameXP - GURU MEDITATION", MB_ICONERROR | MB_TOPMOST | MB_TASKMODAL);
- FatalAppExit(0, L"The application has encountered a critical error and will exit now!");
- TerminateProcess(GetCurrentProcess(), -1);
+ lamexp_fatal_exit(L"The application has encountered a critical error and will exit now!", QWCHAR(QString::fromUtf8(msg)));
}
}
{
Sleep(250);
}
- if(HANDLE thrd = OpenThread(THREAD_TERMINATE, FALSE, g_main_thread_id))
- {
- if(TerminateThread(thrd, -1))
- {
- FatalAppExit(0, L"Not a debug build. Please unload debugger and try again!");
- }
- CloseHandle(thrd);
- }
- TerminateProcess(GetCurrentProcess(), -1);
+ lamexp_fatal_exit(L"Not a debug build. Please unload debugger and try again!");
return 666;
}
{
if(lamexp_check_for_debugger())
{
- FatalAppExit(0, L"Not a debug build. Please unload debugger and try again!");
- TerminateProcess(GetCurrentProcess(), -1);
+ lamexp_fatal_exit(L"Not a debug build. Please unload debugger and try again!");
}
return (HANDLE) _beginthreadex(NULL, 0, lamexp_debug_thread_proc, NULL, 0, NULL);
{
if((!(LAMEXP_DEBUG)) && lamexp_check_for_debugger())
{
- FatalAppExit(0, L"Not a debug build. Please unload debugger and try again!");
- TerminateProcess(GetCurrentProcess(), -1);
+ lamexp_fatal_exit(L"Not a debug build. Please unload debugger and try again!");
}
switch(reinterpret_cast<MSG*>(message)->message)
volatile DWORD retVal = 0xA199B5AF;
if(g_lamexp_entry_check_flag != 0x8761F64D)
{
- FatalAppExit(0, L"Application initialization has failed, take care!");
- TerminateProcess(GetCurrentProcess(), -1);
+ lamexp_fatal_exit(L"Application initialization has failed, take care!");
}
return retVal;
}
{
if((!LAMEXP_DEBUG) && lamexp_check_for_debugger())
{
- FatalAppExit(0, L"Not a debug build. Please unload debugger and try again!");
- TerminateProcess(GetCurrentProcess(), -1);
+ lamexp_fatal_exit(L"Not a debug build. Please unload debugger and try again!");
}
-
if(g_lamexp_entry_check_flag != 0x789E09B2)
{
- FatalAppExit(0, L"Application initialization has failed, take care!");
- TerminateProcess(GetCurrentProcess(), -1);
+ lamexp_fatal_exit(L"Application initialization has failed, take care!");
}
//Zero *before* constructors are called
}
/*
+ * Fatal application exit
+ */
+#pragma intrinsic(_InterlockedExchange)
+void lamexp_fatal_exit(const wchar_t* exitMessage, const wchar_t* errorBoxMessage)
+{
+ static volatile long bFatalFlag = 0L;
+
+ if(_InterlockedExchange(&bFatalFlag, 1L) == 0L)
+ {
+ if(GetCurrentThreadId() != g_main_thread_id)
+ {
+ HANDLE mainThread = OpenThread(THREAD_TERMINATE, FALSE, g_main_thread_id);
+ if(mainThread) TerminateThread(mainThread, ULONG_MAX);
+ }
+
+ if(errorBoxMessage)
+ {
+ MessageBoxW(NULL, errorBoxMessage, L"LameXP - GURU MEDITATION", MB_ICONERROR | MB_TOPMOST | MB_TASKMODAL);
+ }
+
+ for(;;)
+ {
+ FatalAppExit(0, exitMessage);
+ TerminateProcess(GetCurrentProcess(), -1);
+ }
+ }
+}
+
+/*
* Finalization function (final clean-up)
*/
void lamexp_finalization(void)
fflush(stdout);
fflush(stderr);
fprintf(stderr, "\nGURU MEDITATION !!!\n\nException error message: %s\n", error);
- FatalAppExit(0, L"Unhandeled C++ exception error, application will exit!");
- TerminateProcess(GetCurrentProcess(), -1);
+ lamexp_fatal_exit(L"Unhandeled C++ exception error, application will exit!");
}
catch(int error)
{
fflush(stdout);
fflush(stderr);
fprintf(stderr, "\nGURU MEDITATION !!!\n\nException error code: 0x%X\n", error);
- FatalAppExit(0, L"Unhandeled C++ exception error, application will exit!");
- TerminateProcess(GetCurrentProcess(), -1);
+ lamexp_fatal_exit(L"Unhandeled C++ exception error, application will exit!");
}
catch(...)
{
fflush(stdout);
fflush(stderr);
fprintf(stderr, "\nGURU MEDITATION !!!\n");
- FatalAppExit(0, L"Unhandeled C++ exception error, application will exit!");
- TerminateProcess(GetCurrentProcess(), -1);
+ lamexp_fatal_exit(L"Unhandeled C++ exception error, application will exit!");
}
return iResult;
}
fflush(stdout);
fflush(stderr);
fprintf(stderr, "\nGURU MEDITATION !!!\n\nUnhandeled structured exception error! [code: 0x%X]\n", GetExceptionCode());
- FatalAppExit(0, L"Unhandeled structured exception error, application will exit!");
- TerminateProcess(GetCurrentProcess(), -1);
+ lamexp_fatal_exit(L"Unhandeled structured exception error, application will exit!");
}
}
}