Error when printing
-
I have a small program. I compile the executable. If I find the executable and double click on it, everything works fine. I can print, print preview; all is well. If within visual studio I hit the green triangle to run the executable and then I try to print or print preview, I get an error in this code: inline void* CThreadSlotData::GetThreadValue(int nSlot) { EnterCriticalSection(&m_sect); ASSERT(nSlot != 0 && nSlot < m_nMax); ASSERT(m_pSlotData != NULL); ASSERT(m_pSlotData[nSlot].dwFlags & SLOT_USED); ASSERT(m_tlsIndex != (DWORD)-1); if( nSlot <= 0 || nSlot >= m_nMax ) // check for retail builds. { LeaveCriticalSection(&m_sect); return NULL; } CThreadData* pData = (CThreadData*)TlsGetValue(m_tlsIndex); if (pData == NULL || nSlot >= pData->nCount) { LeaveCriticalSection(&m_sect); return NULL; } void* pRetVal = pData->pData[nSlot]; LeaveCriticalSection(&m_sect); return pRetVal; } It breaks at LeaveCriticalSection(). Im really perplexed as to why this error has arisen and what to do to get it to go away. If you have any insight, please let me know.
-
I have a small program. I compile the executable. If I find the executable and double click on it, everything works fine. I can print, print preview; all is well. If within visual studio I hit the green triangle to run the executable and then I try to print or print preview, I get an error in this code: inline void* CThreadSlotData::GetThreadValue(int nSlot) { EnterCriticalSection(&m_sect); ASSERT(nSlot != 0 && nSlot < m_nMax); ASSERT(m_pSlotData != NULL); ASSERT(m_pSlotData[nSlot].dwFlags & SLOT_USED); ASSERT(m_tlsIndex != (DWORD)-1); if( nSlot <= 0 || nSlot >= m_nMax ) // check for retail builds. { LeaveCriticalSection(&m_sect); return NULL; } CThreadData* pData = (CThreadData*)TlsGetValue(m_tlsIndex); if (pData == NULL || nSlot >= pData->nCount) { LeaveCriticalSection(&m_sect); return NULL; } void* pRetVal = pData->pData[nSlot]; LeaveCriticalSection(&m_sect); return pRetVal; } It breaks at LeaveCriticalSection(). Im really perplexed as to why this error has arisen and what to do to get it to go away. If you have any insight, please let me know.
You have already posted this: Print causes in afxtls.cpp - Managed C++/CLI Discussion Boards[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
I have a small program. I compile the executable. If I find the executable and double click on it, everything works fine. I can print, print preview; all is well. If within visual studio I hit the green triangle to run the executable and then I try to print or print preview, I get an error in this code: inline void* CThreadSlotData::GetThreadValue(int nSlot) { EnterCriticalSection(&m_sect); ASSERT(nSlot != 0 && nSlot < m_nMax); ASSERT(m_pSlotData != NULL); ASSERT(m_pSlotData[nSlot].dwFlags & SLOT_USED); ASSERT(m_tlsIndex != (DWORD)-1); if( nSlot <= 0 || nSlot >= m_nMax ) // check for retail builds. { LeaveCriticalSection(&m_sect); return NULL; } CThreadData* pData = (CThreadData*)TlsGetValue(m_tlsIndex); if (pData == NULL || nSlot >= pData->nCount) { LeaveCriticalSection(&m_sect); return NULL; } void* pRetVal = pData->pData[nSlot]; LeaveCriticalSection(&m_sect); return pRetVal; } It breaks at LeaveCriticalSection(). Im really perplexed as to why this error has arisen and what to do to get it to go away. If you have any insight, please let me know.
Erich Ruth wrote:
...I get an error in this code:
What error?
Erich Ruth wrote:
It breaks...
What does that mean, exactly? Could it be a difference between release vs. debug mode? Have you stepped into
LeaveCriticalSection()
to see what is happening (e.g., fired assertion)?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
You have already posted this: Print causes in afxtls.cpp - Managed C++/CLI Discussion Boards[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Richard, but there was just a wrong forum! Therefore (I think) he has reposted the question here....
-
Erich Ruth wrote:
...I get an error in this code:
What error?
Erich Ruth wrote:
It breaks...
What does that mean, exactly? Could it be a difference between release vs. debug mode? Have you stepped into
LeaveCriticalSection()
to see what is happening (e.g., fired assertion)?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
When I say it breaks, that means it pops up a box that says: "Unhandled exemption x 0x777f6a73 in MultiScreen.exe: 0xC0000005: Access violation reading location 0xfeeefefa. and then I have Break or Continue. I hit Break and it shows me this code:
inline void* CThreadSlotData::GetThreadValue(int nSlot)
{
EnterCriticalSection(&m_sect);
ASSERT(nSlot != 0 && nSlot < m_nMax);
ASSERT(m_pSlotData != NULL);
ASSERT(m_pSlotData[nSlot].dwFlags & SLOT_USED);
ASSERT(m_tlsIndex != (DWORD)-1);
if( nSlot <= 0 || nSlot >= m_nMax ) // check for retail builds.
{
LeaveCriticalSection(&m_sect);
return NULL;
}CThreadData\* pData = (CThreadData\*)TlsGetValue(m\_tlsIndex); if (pData == NULL || nSlot >= pData->nCount) { LeaveCriticalSection(&m\_sect); return NULL; } void\* pRetVal = pData->pData\[nSlot\]; LeaveCriticalSection(&m\_sect); return pRetVal;
}
and its pointing to
LeaveCriticalSection(&m_sect);
which is the 2nd to last line.
-
When I say it breaks, that means it pops up a box that says: "Unhandled exemption x 0x777f6a73 in MultiScreen.exe: 0xC0000005: Access violation reading location 0xfeeefefa. and then I have Break or Continue. I hit Break and it shows me this code:
inline void* CThreadSlotData::GetThreadValue(int nSlot)
{
EnterCriticalSection(&m_sect);
ASSERT(nSlot != 0 && nSlot < m_nMax);
ASSERT(m_pSlotData != NULL);
ASSERT(m_pSlotData[nSlot].dwFlags & SLOT_USED);
ASSERT(m_tlsIndex != (DWORD)-1);
if( nSlot <= 0 || nSlot >= m_nMax ) // check for retail builds.
{
LeaveCriticalSection(&m_sect);
return NULL;
}CThreadData\* pData = (CThreadData\*)TlsGetValue(m\_tlsIndex); if (pData == NULL || nSlot >= pData->nCount) { LeaveCriticalSection(&m\_sect); return NULL; } void\* pRetVal = pData->pData\[nSlot\]; LeaveCriticalSection(&m\_sect); return pRetVal;
}
and its pointing to
LeaveCriticalSection(&m_sect);
which is the 2nd to last line.
Hi, 0xfeeefeee is a magic number[^] used by the debug heap for marking memory that's been freed. So it looks like the data at pData->pData[nSlot]; has already been freed by the time you try to read it. This probably means that the bug also exists in your 'Retail build'. A retail build with a normal heap may happily read garbage data and keep on going. You can probably debug this by setting up a memory watch[^] for
&pData->pData[nSlot];
Best Wishes, -David Delaune