点中断停留在以下箭头处,nSlot为负值
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);//nSlot=-17891602
ASSERT(m_tlsIndex != (DWORD)-1);
if( nSlot <= 0 || nSlot >= m_nMax ) // check for retail builds.
{
LeaveCriticalSection(&m_sect);
return NULL;
}自己写的程序里没有多线程序处理,可能出问题的代码贴在下面,该段代码运行结束没问题,退出程序时才报错;
void CInsectsSearchDoc::OnSearch()
{
CString path("C:\\E\\insects\\");
histo_hsv hist1,hist2;
float ranges1[]={ 0, 36 };
float *h_ranges[] = { ranges1 }; /* hue varies from 0 (~0°red) to 180 (~360°red again) */
float ranges2[] = { 0, 32 };
float *s_ranges[] = { ranges2 };
int h_bins = 36, s_bins = 32, v_bins=16;
int hist_size[][3] = {{h_bins}, {s_bins},{v_bins}};
int KNNno[3],KNNsample[3],tempNo,tempSample;
char szWaveletFilename[1024];
char szWaveletTemplateFilename[1024];
double dWaveletThreshold = 0.42;
double dWaveletDistance  = 0,dist;
// TODO: 在此添加命令处理程序代码
IplImage *img,*mask,*imgGray,*subimg;;
IplImage *src=m_image.GetImage();


//preprocess
int width,height;
CvPoint2D32f center; width=src->width;
height=src->height;
center.x=width>>1;
center.y=height>>1; if(width%4!=0)
width-=width%4;
if(height%4!=0)
height-=height%4;

img=cvCreateImage(cvSize(width,height),src->depth,src->nChannels); cvGetRectSubPix( src, img, center);
cvReleaseImage(&src);

mask=getMask(img);

if(mask==NULL)
{
cvReleaseImage(&img);
exit(1);
}

hist1=calcHists(img, mask);
imgGray=cvCreateImage(cvSize(img->width,img->height),8,1);
cvCvtColor( img, imgGray, CV_RGB2GRAY);//转换成灰度图

subimg=segmentROI(imgGray, mask);
cvReleaseImage(&img);
cvReleaseImage(&mask);
cvReleaseImage(&imgGray);
sprintf(szWaveletFilename, "waveletFeat.dat");
generateTemplateWaveletIntoFile(subimg,(std::string)szWaveletFilename);
cvReleaseImage(&subimg);
double corre[3],correlation;
double nndis[3]={1000,1000,1000};
float nnCor[]={0,0,0}; //*/ _variant_t TheValue;
    m_pConnection.CreateInstance(_uuidof(Connection));
//m_pConnection.CreateInstance("ADODB.Connection");
    m_pRecordset.CreateInstance(_uuidof(Recordset));
    try 

// 打开本地的sqlserver数据库 

CString strConnection;
strConnection.Format(_T("Driver={SQL Server};Server=127.0.0.1;DATABASE=insects")); 
m_pConnection->Open((_bstr_t)strConnection, "sa","sa",adConnectUnspecified);
       //访问特征数据库并逐一匹配
strConnection.ReleaseBuffer(); 
m_pRecordset->Open("Select * From features", m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText); 
m_pRecordset->MoveFirst(); 
     


cvReleaseHist(&hist1.h);
cvReleaseHist(&hist1.s); 
m_pRecordset->Close();


catch (_com_error e) 

AfxMessageBox(e.ErrorMessage()); 
}  // 关闭记录集和连接对象 
if (m_pRecordset->State) 
m_pRecordset->Close(); 
if (m_pConnection->State) 
m_pConnection->Close();  m_pRecordset = NULL;
        m_pConnection = NULL;
}请大侠指点迷津,实在找不到解决办法