From: <man...@us...> - 2013-04-09 17:15:20
|
Revision: 1793 http://sourceforge.net/p/modplug/code/1793 Author: manxorist Date: 2013-04-09 17:15:12 +0000 (Tue, 09 Apr 2013) Log Message: ----------- [Ref] Add ALWAYS_ASSERT() which is also active in release builds. [Ref] Convert AudioCriticalSection ASSERTs and CASIODevice ASSERTs to ALWAYS_ASSERT. Modified Paths: -------------- trunk/OpenMPT/common/AudioCriticalSection.cpp trunk/OpenMPT/common/AudioCriticalSection.h trunk/OpenMPT/common/typedefs.h trunk/OpenMPT/mptrack/ExceptionHandler.cpp trunk/OpenMPT/soundlib/Snddev.cpp Modified: trunk/OpenMPT/common/AudioCriticalSection.cpp =================================================================== --- trunk/OpenMPT/common/AudioCriticalSection.cpp 2013-04-09 16:56:45 UTC (rev 1792) +++ trunk/OpenMPT/common/AudioCriticalSection.cpp 2013-04-09 17:15:12 UTC (rev 1793) @@ -12,7 +12,5 @@ #include "../common/AudioCriticalSection.h" CRITICAL_SECTION g_csAudio; -#ifdef _DEBUG int g_csAudioLockCount = 0; -#endif Modified: trunk/OpenMPT/common/AudioCriticalSection.h =================================================================== --- trunk/OpenMPT/common/AudioCriticalSection.h 2013-04-09 16:56:45 UTC (rev 1792) +++ trunk/OpenMPT/common/AudioCriticalSection.h 2013-04-09 17:15:12 UTC (rev 1793) @@ -15,9 +15,7 @@ #include <windows.h> extern CRITICAL_SECTION g_csAudio; -#ifdef _DEBUG extern int g_csAudioLockCount; -#endif // Critical section handling done in (safe) RAII style. // Create a CriticalSection object whenever you need exclusive access to CSoundFile. @@ -40,9 +38,7 @@ { inSection = true; EnterCriticalSection(&g_csAudio); -#ifdef _DEBUG g_csAudioLockCount++; -#endif } }; void Leave() @@ -50,9 +46,7 @@ if(inSection) { inSection = false; -#ifdef _DEBUG g_csAudioLockCount--; -#endif LeaveCriticalSection(&g_csAudio); } }; @@ -63,12 +57,10 @@ static void AssertUnlocked() { // asserts that the critical section is currently not hold by THIS thread -#ifdef _DEBUG if(TryEnterCriticalSection(&g_csAudio)) { - ASSERT(g_csAudioLockCount==0); + ALWAYS_ASSERT(g_csAudioLockCount==0); LeaveCriticalSection(&g_csAudio); } -#endif } }; Modified: trunk/OpenMPT/common/typedefs.h =================================================================== --- trunk/OpenMPT/common/typedefs.h 2013-04-09 16:56:45 UTC (rev 1792) +++ trunk/OpenMPT/common/typedefs.h 2013-04-09 17:15:12 UTC (rev 1793) @@ -38,6 +38,13 @@ #define static_assert(expr, msg) C_ASSERT(expr) #endif +void AlwaysAssertHandler(const char *file, int line, const char *function, const char *expr); +#ifdef NDEBUG +#define ALWAYS_ASSERT(expr) do { if(!(expr)) { if(IsDebuggerPresent()) { ASSERT(expr); } else { AlwaysAssertHandler(__FILE__, __LINE__, __FUNCTION__, #expr); } } } while(0) +#else +#define ALWAYS_ASSERT(expr) ASSERT(expr) +#endif + // Advanced inline attributes #if defined(_MSC_VER) #define forceinline __forceinline Modified: trunk/OpenMPT/mptrack/ExceptionHandler.cpp =================================================================== --- trunk/OpenMPT/mptrack/ExceptionHandler.cpp 2013-04-09 16:56:45 UTC (rev 1792) +++ trunk/OpenMPT/mptrack/ExceptionHandler.cpp 2013-04-09 17:15:12 UTC (rev 1793) @@ -23,27 +23,12 @@ CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam ); -// Try to close the audio device and rescue unsaved work if an unhandled exception occours... -LONG ExceptionHandler::UnhandledExceptionFilter(_EXCEPTION_POINTERS *pExceptionInfo) -//---------------------------------------------------------------------------------- + +static void GenerateDump(CString &errorMessage, _EXCEPTION_POINTERS *pExceptionInfo=NULL) +//--------------------------------------------------------------------------------------- { CMainFrame* pMainFrame = CMainFrame::GetMainFrame(); - // Shut down audio device... - if(pMainFrame) - { - try - { - if(pMainFrame->gpSoundDevice) pMainFrame->gpSoundDevice->Reset(); - pMainFrame->audioCloseDevice(); - } catch(...) - { - } - } - - CString errorMessage; - errorMessage.Format("Unhandled exception 0x%X at address %p occoured.", pExceptionInfo->ExceptionRecord->ExceptionCode, pExceptionInfo->ExceptionRecord->ExceptionAddress); - const CString timestampDir = (CTime::GetCurrentTime()).Format("%Y-%m-%d %H.%M.%S\\"); CString baseRescuePath; { @@ -76,11 +61,14 @@ { _MINIDUMP_EXCEPTION_INFORMATION ExInfo; - ExInfo.ThreadId = ::GetCurrentThreadId(); - ExInfo.ExceptionPointers = pExceptionInfo; - ExInfo.ClientPointers = NULL; + if(pExceptionInfo) + { + ExInfo.ThreadId = ::GetCurrentThreadId(); + ExInfo.ExceptionPointers = pExceptionInfo; + ExInfo.ClientPointers = NULL; + } - pDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL); + pDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, pExceptionInfo ? &ExInfo : NULL, NULL, NULL); ::CloseHandle(hFile); errorMessage.AppendFormat("\n\nDebug information has been saved to\n%s", baseRescuePath); @@ -122,6 +110,41 @@ Reporting::Error(errorMessage, "OpenMPT Crash", pMainFrame); +} + + +// Try to close the audio device and rescue unsaved work if an unhandled exception occours... +LONG ExceptionHandler::UnhandledExceptionFilter(_EXCEPTION_POINTERS *pExceptionInfo) +//---------------------------------------------------------------------------------- +{ + CMainFrame* pMainFrame = CMainFrame::GetMainFrame(); + + // Shut down audio device... + if(pMainFrame) + { + try + { + if(pMainFrame->gpSoundDevice) pMainFrame->gpSoundDevice->Reset(); + pMainFrame->audioCloseDevice(); + } catch(...) + { + } + } + + CString errorMessage; + errorMessage.Format("Unhandled exception 0x%X at address %p occoured.", pExceptionInfo->ExceptionRecord->ExceptionCode, pExceptionInfo->ExceptionRecord->ExceptionAddress); + + GenerateDump(errorMessage, pExceptionInfo); + // Let Windows handle the exception... return EXCEPTION_CONTINUE_SEARCH; } + + +void AlwaysAssertHandler(const char *file, int line, const char *function, const char *expr) +//------------------------------------------------------------------------------------------ +{ + CString errorMessage; + errorMessage.Format("Internal error occured at %s(%d): ASSERT(%s) failed in [%s].", file, line, expr, function); + GenerateDump(errorMessage); +} Modified: trunk/OpenMPT/soundlib/Snddev.cpp =================================================================== --- trunk/OpenMPT/soundlib/Snddev.cpp 2013-04-09 16:56:45 UTC (rev 1792) +++ trunk/OpenMPT/soundlib/Snddev.cpp 2013-04-09 17:15:12 UTC (rev 1793) @@ -879,9 +879,7 @@ static DWORD g_dwBuffer = 0; -#ifdef _DEBUG static int g_asio_startcount = 0; -#endif BOOL CASIODevice::EnumerateDevices(UINT nIndex, LPSTR pszDescription, UINT cbSize) @@ -1134,10 +1132,8 @@ { if (IsOpen()) { -#ifdef _DEBUG - ASSERT(g_asio_startcount==0); + ALWAYS_ASSERT(g_asio_startcount==0); g_asio_startcount++; -#endif InterlockedExchange(&m_RenderSilence, 0); if(!m_bMixRunning) @@ -1161,10 +1157,8 @@ if (IsOpen()) { InterlockedExchange(&m_RenderSilence, 1); -#ifdef _DEBUG g_asio_startcount--; - ASSERT(g_asio_startcount==0); -#endif + ALWAYS_ASSERT(g_asio_startcount==0); } } @@ -1217,9 +1211,7 @@ { CASIODevice::ReportASIOException("ASIO crash in stop()\n"); } -#ifdef _DEBUG g_asio_startcount = 0; -#endif InterlockedExchange(&m_RenderSilence, 0); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |