diff --git a/Source/appfat.cpp b/Source/appfat.cpp index d9c908a8b..427110f46 100644 --- a/Source/appfat.cpp +++ b/Source/appfat.cpp @@ -13,6 +13,41 @@ int cleanup_thread_id; // } //} +void TriggerBreak() +{ +#ifdef _DEBUG + LPTOP_LEVEL_EXCEPTION_FILTER pFilter; + + pFilter = SetUnhandledExceptionFilter(BreakFilter); +#ifdef USE_ASM + __asm { + int 3 + } +#else + __debugbreak(); +#endif + SetUnhandledExceptionFilter(pFilter); +#endif +} + +#ifdef _DEBUG +LONG __stdcall BreakFilter(PEXCEPTION_POINTERS pExc) +{ + if(pExc->ExceptionRecord == NULL) { + return 0; + } + if(pExc->ExceptionRecord->ExceptionCode != EXCEPTION_BREAKPOINT) { + return 0; + } + + if(((BYTE *)pExc->ContextRecord->Eip)[0] == 0xCC) { // int 3 + pExc->ContextRecord->Eip++; + } + + return -1; +} +#endif + char *GetErrorStr(DWORD error_code) { DWORD upper_code; @@ -421,6 +456,9 @@ void __cdecl app_fatal(const char *pszFmt, ...) va_start(va, pszFmt); FreeDlg(); +#ifdef _DEBUG + TriggerBreak(); +#endif if (pszFmt) MsgBox(pszFmt, va); diff --git a/Source/appfat.h b/Source/appfat.h index bab1a4c2c..77d9c620a 100644 --- a/Source/appfat.h +++ b/Source/appfat.h @@ -6,6 +6,10 @@ extern char sz_error_buf[256]; extern int terminating; // weak extern int cleanup_thread_id; // weak +void TriggerBreak(); +#ifdef _DEBUG +LONG __stdcall BreakFilter(PEXCEPTION_POINTERS pExc); +#endif char *GetErrorStr(DWORD error_code); void TraceErrorDD(HRESULT hError, char *pszBuffer, DWORD dwMaxChars); void TraceErrorDS(HRESULT hError, char *pszBuffer, DWORD dwMaxChars); diff --git a/Source/dx.cpp b/Source/dx.cpp index 89395019d..fea1fdff3 100644 --- a/Source/dx.cpp +++ b/Source/dx.cpp @@ -59,7 +59,7 @@ void dx_init(HWND hWnd) hDDVal = lpDDInterface->lpVtbl->SetCooperativeLevel(lpDDInterface, hWnd, DDSCL_NORMAL | DDSCL_ALLOWREBOOT); #endif if(hDDVal == DDERR_EXCLUSIVEMODEALREADYSET) { - break_exception(); + TriggerBreak(); } else if(hDDVal != DD_OK) { ErrDlg(IDD_DIALOG1, hDDVal, "C:\\Diablo\\Direct\\dx.cpp", 155); } @@ -71,7 +71,7 @@ void dx_init(HWND hWnd) hDDVal = lpDDInterface->lpVtbl->SetCooperativeLevel(lpDDInterface, hWnd, DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT | DDSCL_FULLSCREEN); #endif if(hDDVal == DDERR_EXCLUSIVEMODEALREADYSET) { - break_exception(); + TriggerBreak(); } else if(hDDVal != DD_OK) { ErrDlg(IDD_DIALOG1, hDDVal, "C:\\Src\\Diablo\\Source\\dx.cpp", 170); } diff --git a/Source/fault.cpp b/Source/fault.cpp index 0389c4dda..459a724b1 100644 --- a/Source/fault.cpp +++ b/Source/fault.cpp @@ -32,17 +32,6 @@ LPTOP_LEVEL_EXCEPTION_FILTER __cdecl fault_cleanup_filter() return fault_reset_filter(&fault_unused); } -void break_exception() -{ -/* - LPTOP_LEVEL_EXCEPTION_FILTER pFilter; - - pFilter = SetUnhandledExceptionFilter(TopLevelExceptionFilter); - __asm int 3 - SetUnhandledExceptionFilter(pFilter); -*/ -} - LONG __stdcall TopLevelExceptionFilter(PEXCEPTION_POINTERS ExceptionInfo) { PEXCEPTION_RECORD xcpt; diff --git a/Source/fault.h b/Source/fault.h index 5b5c6250a..ec669c7ac 100644 --- a/Source/fault.h +++ b/Source/fault.h @@ -13,7 +13,6 @@ extern LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter; void fault_init_filter(); void fault_cleanup_filter_atexit(); LPTOP_LEVEL_EXCEPTION_FILTER __cdecl fault_cleanup_filter(); -void break_exception(); LONG __stdcall TopLevelExceptionFilter(PEXCEPTION_POINTERS ExceptionInfo); void fault_hex_format(BYTE *ptr, unsigned int numBytes); void fault_unknown_module(LPCVOID lpAddress, LPSTR lpModuleName, int iMaxLength, int *sectionNum, int *sectionOffset);