Counter Strike : Global Offensive Source Code
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.

64 lines
1.5 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "bitbuf.h"
  8. #include "bitbuf_errorhandler.h"
  9. #include "tier0/dbg.h"
  10. #include "tier0/threadtools.h"
  11. #include "utlsymbol.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. static CUtlSymbolTable g_ErrorNames[BITBUFERROR_NUM_ERRORS];
  15. // This is needed to make bf_write / bf_read thread safe;
  16. // this error case is expected to happen rarely.
  17. static CThreadRWLock g_ErrorNamesLock;
  18. void EngineBitBufErrorHandler( BitBufErrorType errorType, const char *pDebugName )
  19. {
  20. if ( !pDebugName )
  21. {
  22. pDebugName = "(unknown)";
  23. }
  24. // Only print an error a couple times.
  25. g_ErrorNamesLock.LockForRead();
  26. CUtlSymbol sym = g_ErrorNames[ errorType ].Find( pDebugName );
  27. g_ErrorNamesLock.UnlockRead();
  28. if ( UTL_INVAL_SYMBOL == sym )
  29. {
  30. g_ErrorNamesLock.LockForWrite();
  31. g_ErrorNames[ errorType ].AddString( pDebugName );
  32. g_ErrorNamesLock.UnlockWrite();
  33. if ( errorType == BITBUFERROR_VALUE_OUT_OF_RANGE )
  34. {
  35. Warning( "Error in bitbuf [%s]: out of range value. Debug in bitbuf_errorhandler.cpp\n", pDebugName );
  36. }
  37. else if ( errorType == BITBUFERROR_BUFFER_OVERRUN )
  38. {
  39. Warning( "Error in bitbuf [%s]: buffer overrun. Debug in bitbuf_errorhandler.cpp\n", pDebugName );
  40. }
  41. }
  42. Assert( 0 );
  43. }
  44. void InstallBitBufErrorHandler()
  45. {
  46. SetBitBufErrorHandler( EngineBitBufErrorHandler );
  47. }