|
|
|
@ -3,18 +3,17 @@
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
|
|
#ifdef Y_PLATFORM_WINDOWS
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN 1
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
#include "windows_headers.h"
|
|
|
|
|
#include <intrin.h>
|
|
|
|
|
#include <tlhelp32.h>
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static std::mutex s_AssertFailedMutex;
|
|
|
|
|
|
|
|
|
|
static inline void FreezeThreads(void** ppHandle)
|
|
|
|
|
{
|
|
|
|
|
#ifdef Y_PLATFORM_WINDOWS
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
|
|
|
|
|
if (hSnapshot != INVALID_HANDLE_VALUE)
|
|
|
|
|
{
|
|
|
|
@ -44,7 +43,7 @@ static inline void FreezeThreads(void** ppHandle)
|
|
|
|
|
|
|
|
|
|
static inline void ResumeThreads(void* pHandle)
|
|
|
|
|
{
|
|
|
|
|
#ifdef Y_PLATFORM_WINDOWS
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
HANDLE hSnapshot = (HANDLE)pHandle;
|
|
|
|
|
if (pHandle != INVALID_HANDLE_VALUE)
|
|
|
|
|
{
|
|
|
|
@ -80,13 +79,16 @@ void Y_OnAssertFailed(const char* szMessage, const char* szFunction, const char*
|
|
|
|
|
char szMsg[512];
|
|
|
|
|
std::snprintf(szMsg, sizeof(szMsg), "%s in function %s (%s:%u)", szMessage, szFunction, szFile, uLine);
|
|
|
|
|
|
|
|
|
|
#ifdef Y_PLATFORM_WINDOWS
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
SetConsoleTextAttribute(GetStdHandle(STD_ERROR_HANDLE), FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
|
|
|
|
|
WriteConsoleA(GetStdHandle(STD_ERROR_HANDLE), szMsg, Y_strlen(szMsg), NULL, NULL);
|
|
|
|
|
WriteConsoleA(GetStdHandle(STD_ERROR_HANDLE), szMsg, static_cast<DWORD>(std::strlen(szMsg)), NULL, NULL);
|
|
|
|
|
OutputDebugStringA(szMsg);
|
|
|
|
|
|
|
|
|
|
Y_strncat(szMsg, sizeof(szMsg),
|
|
|
|
|
"\n\nPress Abort to exit, Retry to break to debugger, or Ignore to attempt to continue.");
|
|
|
|
|
std::snprintf(
|
|
|
|
|
szMsg, sizeof(szMsg),
|
|
|
|
|
"%s in function %s (%s:%u)\n\nPress Abort to exit, Retry to break to debugger, or Ignore to attempt to continue.",
|
|
|
|
|
szMessage, szFunction, szFile, uLine);
|
|
|
|
|
|
|
|
|
|
int result = MessageBoxA(NULL, szMsg, NULL, MB_ABORTRETRYIGNORE | MB_ICONERROR);
|
|
|
|
|
if (result == IDRETRY)
|
|
|
|
|
__debugbreak();
|
|
|
|
@ -112,13 +114,16 @@ void Y_OnPanicReached(const char* szMessage, const char* szFunction, const char*
|
|
|
|
|
char szMsg[512];
|
|
|
|
|
std::snprintf(szMsg, sizeof(szMsg), "%s in function %s (%s:%u)", szMessage, szFunction, szFile, uLine);
|
|
|
|
|
|
|
|
|
|
#ifdef Y_PLATFORM_WINDOWS
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
SetConsoleTextAttribute(GetStdHandle(STD_ERROR_HANDLE), FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
|
|
|
|
|
WriteConsoleA(GetStdHandle(STD_ERROR_HANDLE), szMsg, Y_strlen(szMsg), NULL, NULL);
|
|
|
|
|
WriteConsoleA(GetStdHandle(STD_ERROR_HANDLE), szMsg, static_cast<DWORD>(std::strlen(szMsg)), NULL, NULL);
|
|
|
|
|
OutputDebugStringA(szMsg);
|
|
|
|
|
|
|
|
|
|
Y_strncat(szMsg, sizeof(szMsg),
|
|
|
|
|
"\n\nDo you want to attempt to break into a debugger? Pressing Cancel will abort the application.");
|
|
|
|
|
std::snprintf(szMsg, sizeof(szMsg),
|
|
|
|
|
"%s in function %s (%s:%u)\n\nDo you want to attempt to break into a debugger? Pressing Cancel will "
|
|
|
|
|
"abort the application.",
|
|
|
|
|
szMessage, szFunction, szFile, uLine);
|
|
|
|
|
|
|
|
|
|
int result = MessageBoxA(NULL, szMsg, NULL, MB_OKCANCEL | MB_ICONERROR);
|
|
|
|
|
if (result == IDOK)
|
|
|
|
|
__debugbreak();
|
|
|
|
|