L
Lee Staniforth
Guest
Hi, all,
I have an application written in C++. We are using Visual Studio 2013 Visual C++ to develop on Windows.
The application works fine when developed on Windows 7. We are in the process of porting over to develop on Windows 10, and have an issue. It appears the DebugInfo part of the CriticalSection isn't initialised correctly on Windows 10.
This causes the application to crash when trying to print out some debug information when the Debug version of the application is run.
Here's some code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~
CLDAPResultList::CLDAPResultList()
{
InitializeCriticalSection(&m_cs);
}
CLDAPResultList::~CLDAPResultList()
{
Reset();
DeleteCriticalSection(&m_cs);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~
#ifdef _DEBUG
#define DeleteCriticalSection(cs) TraceDeleteCriticalSection(cs, __FILE__, __LINE__)
#endif // _DEBUG
~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~
#ifdef _DEBUG
void TraceDeleteCriticalSection(CRITICAL_SECTION *crit, char *sFile, int nLine)
{
if (crit->DebugInfo->ContentionCount)
TRACEwprintf(MDSUtils(), L"Lock Contentions: %d (%S, %d)\n", crit->DebugInfo->ContentionCount, sFile, nLine);
DeleteCriticalSection(crit);
}
#endif // _DEBUG
~~~~~~~~~~~~~~~~~~~~~~~~~~~
So, when running the Debug version, the TraceDeleteCriticalSection() crashes as the crit->DebugInfo->ContentionCount is accessed. This is because ->DebugInfo isn't initialized.
Stopping the debugger on the call of InitializeCriticalSection(), I can see the value of m_cs->DebugInfo change to 0xffffffffffffffff on Windows 10. Whereas on Windows 7, is has an address.
To workaround this, I have tried changing the definition of InitializeCriticalSection() to force the DebugInfo to be initialised:
#define InitializeCriticalSection(cs) InitializeCriticalSectionEx(cs, 0, RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO)
This works fine on Windows 10, but fails on Windows 7.
I'd appreciate any suggestions. I need the application to work in Debug mode on both Windows 7 and Windows 10.
Thanks in advance.
lee
Continue reading...
I have an application written in C++. We are using Visual Studio 2013 Visual C++ to develop on Windows.
The application works fine when developed on Windows 7. We are in the process of porting over to develop on Windows 10, and have an issue. It appears the DebugInfo part of the CriticalSection isn't initialised correctly on Windows 10.
This causes the application to crash when trying to print out some debug information when the Debug version of the application is run.
Here's some code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~
CLDAPResultList::CLDAPResultList()
{
InitializeCriticalSection(&m_cs);
}
CLDAPResultList::~CLDAPResultList()
{
Reset();
DeleteCriticalSection(&m_cs);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~
#ifdef _DEBUG
#define DeleteCriticalSection(cs) TraceDeleteCriticalSection(cs, __FILE__, __LINE__)
#endif // _DEBUG
~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~
#ifdef _DEBUG
void TraceDeleteCriticalSection(CRITICAL_SECTION *crit, char *sFile, int nLine)
{
if (crit->DebugInfo->ContentionCount)
TRACEwprintf(MDSUtils(), L"Lock Contentions: %d (%S, %d)\n", crit->DebugInfo->ContentionCount, sFile, nLine);
DeleteCriticalSection(crit);
}
#endif // _DEBUG
~~~~~~~~~~~~~~~~~~~~~~~~~~~
So, when running the Debug version, the TraceDeleteCriticalSection() crashes as the crit->DebugInfo->ContentionCount is accessed. This is because ->DebugInfo isn't initialized.
Stopping the debugger on the call of InitializeCriticalSection(), I can see the value of m_cs->DebugInfo change to 0xffffffffffffffff on Windows 10. Whereas on Windows 7, is has an address.
To workaround this, I have tried changing the definition of InitializeCriticalSection() to force the DebugInfo to be initialised:
#define InitializeCriticalSection(cs) InitializeCriticalSectionEx(cs, 0, RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO)
This works fine on Windows 10, but fails on Windows 7.
I'd appreciate any suggestions. I need the application to work in Debug mode on both Windows 7 and Windows 10.
Thanks in advance.
lee
Continue reading...