Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
1.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "stdafx.h"
  9. #ifdef _PSEUDO_DEBUG // entire file
  10. #ifdef _PSEUDO_DEBUG
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. LONG AssertBusy = -1;
  15. LONG AssertReallyBusy = -1;
  16. BOOL AssertFailedLine(LPCSTR lpszFileName, int nLine)
  17. {
  18. TCHAR szMessage[_MAX_PATH*2];
  19. InterlockedDecrement(&AssertReallyBusy);
  20. // format message into buffer
  21. wsprintf(szMessage, _T("File %hs, Line %d"),
  22. lpszFileName, nLine);
  23. TCHAR szT[_MAX_PATH*2 + 20];
  24. wsprintf(szT, _T("Assertion Failed: %s\n"), szMessage);
  25. OutputDebugString(szT);
  26. if (InterlockedIncrement(&AssertBusy) > 0)
  27. {
  28. InterlockedDecrement(&AssertBusy);
  29. // assert within assert (examine call stack to determine first one)
  30. DebugBreak();
  31. return FALSE;
  32. }
  33. // active popup window for the current thread
  34. HWND hWndParent = GetActiveWindow();
  35. if (hWndParent != NULL)
  36. hWndParent = GetLastActivePopup(hWndParent);
  37. // display the assert
  38. int nCode = ::MessageBox(hWndParent, szMessage, _T("Assertion Failed!"),
  39. MB_TASKMODAL|MB_ICONHAND|MB_ABORTRETRYIGNORE|MB_SETFOREGROUND);
  40. // cleanup
  41. InterlockedDecrement(&AssertBusy);
  42. if (nCode == IDIGNORE)
  43. return FALSE; // ignore
  44. if (nCode == IDRETRY)
  45. return TRUE; // will cause DebugBreak
  46. AfxAbort(); // should not return (but otherwise DebugBreak)
  47. return TRUE;
  48. }
  49. void Trace(LPCTSTR lpszFormat, ...)
  50. {
  51. va_list args;
  52. va_start(args, lpszFormat);
  53. int nBuf;
  54. TCHAR szBuffer[512];
  55. nBuf = _vstprintf(szBuffer, lpszFormat, args);
  56. ASSERT(nBuf < (sizeof(szBuffer)/sizeof(szBuffer[0])));
  57. CString strMessage;
  58. if (AfxGetApp() != NULL)
  59. strMessage = ((CString) (AfxGetApp()->m_pszExeName)) + _T(": ");
  60. strMessage += szBuffer;
  61. OutputDebugString(strMessage);
  62. va_end(args);
  63. }
  64. #endif // _PSEUDO_DEBUG