按F5调试release版本程序,还没进行APP类的构造函数,就出现未处理异常,跟踪进去,发现在下面一个函数出错: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);
// 在下面出错,nSlot 等于0
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;
}
上网查了下,发现GetThreadValue用来获取调用线程的第slot个线程局部变量的值。请问为什么会有这个错误呢?如何解决这个错误呢?编译环境:VS C++2005 ,Win XP sp2.
{
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);
// 在下面出错,nSlot 等于0
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;
}
上网查了下,发现GetThreadValue用来获取调用线程的第slot个线程局部变量的值。请问为什么会有这个错误呢?如何解决这个错误呢?编译环境:VS C++2005 ,Win XP sp2.
建议先在debug下仔细调试下,在什么地方出的错
如果是, 保持这两个工程用同一个运行时库, 具体在project > settings > c/c++ > code generation , 选择单线程, 多线程库...
如果是, 保持这两个工程用同一个运行时库, 具体在project > settings > c/c++ > code generation , 选择单线程, 多线程库...Up
Up
// 在下面出错,nSlot 等于0这个函数里面有断言,nSlot应该是不能等于0的
你传个0的参数进去,肯定会有异常的
debug调试下没有问题,可以正常启动。