From: <man...@us...> - 2013-05-03 14:49:39
|
Revision: 2006 http://sourceforge.net/p/modplug/code/2006 Author: manxorist Date: 2013-05-03 14:49:28 +0000 (Fri, 03 May 2013) Log Message: ----------- [Ref] Try to improve debug messages in CASIODevice. Modified Paths: -------------- trunk/OpenMPT/common/AudioCriticalSection.h trunk/OpenMPT/common/typedefs.cpp trunk/OpenMPT/common/typedefs.h trunk/OpenMPT/mptrack/ExceptionHandler.cpp trunk/OpenMPT/sounddev/SoundDevice.cpp trunk/OpenMPT/sounddev/SoundDevices.h Modified: trunk/OpenMPT/common/AudioCriticalSection.h =================================================================== --- trunk/OpenMPT/common/AudioCriticalSection.h 2013-05-02 23:28:58 UTC (rev 2005) +++ trunk/OpenMPT/common/AudioCriticalSection.h 2013-05-03 14:49:28 UTC (rev 2006) @@ -56,15 +56,21 @@ { Leave(); }; - static void AssertUnlocked() + static bool IsLocked() // DEBUGGING only { - // asserts that the critical section is currently not hold by THIS thread + bool islocked = false; if(TryEnterCriticalSection(&g_csAudio)) { - ALWAYS_ASSERT(g_csAudioLockCount==0); + islocked = (g_csAudioLockCount > 0); LeaveCriticalSection(&g_csAudio); } + return islocked; } + static void AssertUnlocked() + { + // asserts that the critical section is currently not hold by THIS thread + ALWAYS_ASSERT(!IsLocked()); + } }; #else // !MODPLUG_TRACKER Modified: trunk/OpenMPT/common/typedefs.cpp =================================================================== --- trunk/OpenMPT/common/typedefs.cpp 2013-05-02 23:28:58 UTC (rev 2005) +++ trunk/OpenMPT/common/typedefs.cpp 2013-05-03 14:49:28 UTC (rev 2006) @@ -14,16 +14,29 @@ #ifndef MODPLUG_TRACKER -void AlwaysAssertHandler(const char *file, int line, const char *function, const char *expr) -//------------------------------------------------------------------------------------------ +void AlwaysAssertHandler(const char *file, int line, const char *function, const char *expr, const char *msg) +//----------------------------------------------------------------------------------------------------------- { - std::cerr - << "openmpt: ASSERTION FAILED: " - << file << "(" << line << ")" << ": " - << std::string(expr) - << " [" << function << "]" - << std::endl - ; + if(msg) + { + std::cerr + << "openmpt: ASSERTION FAILED: " + << file << "(" << line << ")" << ": " + << msg + << " (" << std::string(expr) << ") " + << " [" << function << "]" + << std::endl + ; + } else + { + std::cerr + << "openmpt: ASSERTION FAILED: " + << file << "(" << line << ")" << ": " + << std::string(expr) + << " [" << function << "]" + << std::endl + ; + } } #endif Modified: trunk/OpenMPT/common/typedefs.h =================================================================== --- trunk/OpenMPT/common/typedefs.h 2013-05-02 23:28:58 UTC (rev 2005) +++ trunk/OpenMPT/common/typedefs.h 2013-05-03 14:49:28 UTC (rev 2006) @@ -119,9 +119,11 @@ #if defined(_DEBUG) #define ALWAYS_ASSERT(expr) ASSERT(expr) +#define ALWAYS_ASSERT_WARN_MESSAGE(expr,msg) ASSERT(expr) #else -void AlwaysAssertHandler(const char *file, int line, const char *function, const char *expr); +void AlwaysAssertHandler(const char *file, int line, const char *function, const char *expr, const char *msg=nullptr); #define ALWAYS_ASSERT(expr) do { if(!(expr)) { AlwaysAssertHandler(__FILE__, __LINE__, __FUNCTION__, #expr); } } while(0) +#define ALWAYS_ASSERT_WARN_MESSAGE(expr,msg) do { if(!(expr)) { AlwaysAssertHandler(__FILE__, __LINE__, __FUNCTION__, #expr, msg); } } while(0) #endif // Compile time assert. Modified: trunk/OpenMPT/mptrack/ExceptionHandler.cpp =================================================================== --- trunk/OpenMPT/mptrack/ExceptionHandler.cpp 2013-05-02 23:28:58 UTC (rev 2005) +++ trunk/OpenMPT/mptrack/ExceptionHandler.cpp 2013-05-03 14:49:28 UTC (rev 2006) @@ -25,9 +25,15 @@ ); -static void GenerateDump(CString &errorMessage, _EXCEPTION_POINTERS *pExceptionInfo=NULL) -//--------------------------------------------------------------------------------------- +enum DumpMode { + DumpModeCrash = 0, + DumpModeWarning = 1, +}; + +static void GenerateDump(CString &errorMessage, _EXCEPTION_POINTERS *pExceptionInfo=NULL, DumpMode mode=DumpModeCrash) +//-------------------------------------------------------------------------------------------------------------------- +{ CMainFrame* pMainFrame = CMainFrame::GetMainFrame(); const CString timestampDir = (CTime::GetCurrentTime()).Format("%Y-%m-%d %H.%M.%S\\"); @@ -114,7 +120,13 @@ MptVersion::GetVersionUrlString().c_str() ); - Reporting::Error(errorMessage, "OpenMPT Crash", pMainFrame); + if(mode == DumpModeWarning) + { + Reporting::Error(errorMessage, "OpenMPT Warning", pMainFrame); + } else + { + Reporting::Error(errorMessage, "OpenMPT Crash", pMainFrame); + } } @@ -151,8 +163,9 @@ #ifndef _DEBUG -void AlwaysAssertHandler(const char *file, int line, const char *function, const char *expr) -//------------------------------------------------------------------------------------------ + +void AlwaysAssertHandler(const char *file, int line, const char *function, const char *expr, const char *msg) +//----------------------------------------------------------------------------------------------------------- { if(IsDebuggerPresent()) { @@ -162,10 +175,19 @@ DebugBreak(); } else { - CString errorMessage; - errorMessage.Format("Internal error occured at %s(%d): ASSERT(%s) failed in [%s].", file, line, expr, function); - GenerateDump(errorMessage); + if(msg) + { + CString errorMessage; + errorMessage.Format("Internal state inconsistency detected at %s(%d). This is just a warning that could potentially lead to a crash later on: %s [%s].", file, line, msg, function); + GenerateDump(errorMessage, NULL, DumpModeWarning); + } else + { + CString errorMessage; + errorMessage.Format("Internal error occured at %s(%d): ASSERT(%s) failed in [%s].", file, line, expr, function); + GenerateDump(errorMessage); + } } } + #endif Modified: trunk/OpenMPT/sounddev/SoundDevice.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-05-02 23:28:58 UTC (rev 2005) +++ trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-05-03 14:49:28 UTC (rev 2006) @@ -19,7 +19,10 @@ #endif #include "../common/StringFixer.h" +// DEBUG: +#include "../common/AudioCriticalSection.h" + /////////////////////////////////////////////////////////////////////////////////////// // // ISoundDevice base class @@ -1165,16 +1168,39 @@ } -void CASIODevice::WaitForRenderSilenceUpdated(bool on) -//---------------------------------------------------- +void CASIODevice::SetRenderSilence(bool silence, bool wait) +//--------------------------------------------------------- { + InterlockedExchange(&m_RenderSilence, silence?1:0); + if(!wait) + { + return; + } DWORD pollingstart = GetTickCount(); - while(InterlockedExchangeAdd(&m_RenderingSilence, 0) != (on?1:0)) + while(InterlockedExchangeAdd(&m_RenderingSilence, 0) != (silence?1:0)) { Sleep(1); - if(GetTickCount() - pollingstart > 250) + if(GetTickCount() - pollingstart > 1000) { - ALWAYS_ASSERT(false && "waiting for asio failed"); + if(silence) + { + if(CriticalSection::IsLocked()) + { + ALWAYS_ASSERT_WARN_MESSAGE(false, "AudioCriticalSection locked while stopping ASIO"); + } else + { + ALWAYS_ASSERT_WARN_MESSAGE(false, "waiting for asio failed in Stop()"); + } + } else + { + if(CriticalSection::IsLocked()) + { + ALWAYS_ASSERT_WARN_MESSAGE(false, "AudioCriticalSection locked while starting ASIO"); + } else + { + ALWAYS_ASSERT_WARN_MESSAGE(false, "waiting for asio failed in Start()"); + } + } break; } } @@ -1184,12 +1210,14 @@ void CASIODevice::InternalStart() //------------------------------- { + ALWAYS_ASSERT_WARN_MESSAGE(!CriticalSection::IsLocked(), "AudioCriticalSection locked while starting ASIO"); + ALWAYS_ASSERT(g_asio_startcount==0); g_asio_startcount++; - InterlockedExchange(&m_RenderSilence, 0); if(!m_bMixRunning) { + SetRenderSilence(false); m_bMixRunning = TRUE; try { @@ -1197,10 +1225,11 @@ } catch(...) { CASIODevice::ReportASIOException("ASIO crash in start()\n"); + m_bMixRunning = FALSE; } } else { - WaitForRenderSilenceUpdated(false); + SetRenderSilence(false, true); } } @@ -1208,8 +1237,10 @@ void CASIODevice::InternalStop() //------------------------------ { - InterlockedExchange(&m_RenderSilence, 1); - WaitForRenderSilenceUpdated(true); + ALWAYS_ASSERT(g_asio_startcount==1); + ALWAYS_ASSERT_WARN_MESSAGE(!CriticalSection::IsLocked(), "AudioCriticalSection locked while stopping ASIO"); + + SetRenderSilence(true, true); g_asio_startcount--; ALWAYS_ASSERT(g_asio_startcount==0); } @@ -1223,6 +1254,7 @@ if (m_bMixRunning) { m_bMixRunning = FALSE; + ALWAYS_ASSERT(g_asio_startcount==1 || g_asio_startcount==0); try { m_pAsioDrv->stop(); @@ -1231,6 +1263,7 @@ CASIODevice::ReportASIOException("ASIO crash in stop()\n"); } } + SetRenderSilence(false); try { m_pAsioDrv->disposeBuffers(); @@ -1254,6 +1287,7 @@ if(m_bMixRunning) { m_bMixRunning = FALSE; + ALWAYS_ASSERT(g_asio_startcount==1 || g_asio_startcount==0); try { m_pAsioDrv->stop(); @@ -1262,7 +1296,7 @@ CASIODevice::ReportASIOException("ASIO crash in stop()\n"); } g_asio_startcount = 0; - InterlockedExchange(&m_RenderSilence, 0); + SetRenderSilence(false); } } @@ -1435,7 +1469,13 @@ //---------------------------------------------------------------------------- { UNREFERENCED_PARAMETER(directProcess); - if(gpCurrentAsio) gpCurrentAsio->BufferSwitch(doubleBufferIndex); + if(gpCurrentAsio) + { + gpCurrentAsio->BufferSwitch(doubleBufferIndex); + } else + { + ALWAYS_ASSERT(false && "gpCurrentAsio"); + } } Modified: trunk/OpenMPT/sounddev/SoundDevices.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevices.h 2013-05-02 23:28:58 UTC (rev 2005) +++ trunk/OpenMPT/sounddev/SoundDevices.h 2013-05-03 14:49:28 UTC (rev 2006) @@ -197,7 +197,7 @@ int m_FrameBuffer[ASIO_BLOCK_LEN]; private: - void WaitForRenderSilenceUpdated(bool on); + void SetRenderSilence(bool silence, bool wait=false); public: static int baseChannel; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |