summaryrefslogtreecommitdiff
path: root/utils/valvelib/debug.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /utils/valvelib/debug.cpp
downloadarchived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.tar.xz
archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.zip
Diffstat (limited to 'utils/valvelib/debug.cpp')
-rw-r--r--utils/valvelib/debug.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/utils/valvelib/debug.cpp b/utils/valvelib/debug.cpp
new file mode 100644
index 0000000..df54867
--- /dev/null
+++ b/utils/valvelib/debug.cpp
@@ -0,0 +1,87 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//
+//=============================================================================//
+#include "stdafx.h"
+
+#ifdef _PSEUDO_DEBUG // entire file
+
+#ifdef _PSEUDO_DEBUG
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+#endif
+
+LONG AssertBusy = -1;
+LONG AssertReallyBusy = -1;
+
+BOOL AssertFailedLine(LPCSTR lpszFileName, int nLine)
+{
+ TCHAR szMessage[_MAX_PATH*2];
+
+ InterlockedDecrement(&AssertReallyBusy);
+
+ // format message into buffer
+ wsprintf(szMessage, _T("File %hs, Line %d"),
+ lpszFileName, nLine);
+
+ TCHAR szT[_MAX_PATH*2 + 20];
+ wsprintf(szT, _T("Assertion Failed: %s\n"), szMessage);
+ OutputDebugString(szT);
+
+ if (InterlockedIncrement(&AssertBusy) > 0)
+ {
+ InterlockedDecrement(&AssertBusy);
+
+ // assert within assert (examine call stack to determine first one)
+ DebugBreak();
+ return FALSE;
+ }
+
+ // active popup window for the current thread
+ HWND hWndParent = GetActiveWindow();
+ if (hWndParent != NULL)
+ hWndParent = GetLastActivePopup(hWndParent);
+
+ // display the assert
+ int nCode = ::MessageBox(hWndParent, szMessage, _T("Assertion Failed!"),
+ MB_TASKMODAL|MB_ICONHAND|MB_ABORTRETRYIGNORE|MB_SETFOREGROUND);
+
+ // cleanup
+ InterlockedDecrement(&AssertBusy);
+
+ if (nCode == IDIGNORE)
+ return FALSE; // ignore
+
+ if (nCode == IDRETRY)
+ return TRUE; // will cause DebugBreak
+
+ AfxAbort(); // should not return (but otherwise DebugBreak)
+ return TRUE;
+}
+
+void Trace(LPCTSTR lpszFormat, ...)
+{
+ va_list args;
+ va_start(args, lpszFormat);
+
+ int nBuf;
+ TCHAR szBuffer[512];
+
+ nBuf = _vstprintf(szBuffer, lpszFormat, args);
+ ASSERT(nBuf < (sizeof(szBuffer)/sizeof(szBuffer[0])));
+
+ CString strMessage;
+
+ if (AfxGetApp() != NULL)
+ strMessage = ((CString) (AfxGetApp()->m_pszExeName)) + _T(": ");
+ strMessage += szBuffer;
+ OutputDebugString(strMessage);
+
+ va_end(args);
+}
+
+
+#endif // _PSEUDO_DEBUG