Multithreaded Qt Application Crashing Windows
Well The problem is quite complex. I don't know where to start. My Application runs 4 threads DGRDPClientThread
.
a DGRDPClientThread
has 1 DGRegion
which has QList<DGRect*>
.
at 1000 ms
Interval DGRDPClientThread::tick()
is invoked which calls _region->update()
void DGRegion::update() const{
foreach(DGRect* rect, rects){
if(rect->scan() != 0){
mutex.lock();
QByteArray buffer = rect->serialize();
//socket->send(buffer);
qDebug() << buffer;
mutex.unlock();
}
}
}
rect->scan()
reads a rectangul开发者_开发百科ar area of screen in a char* buffer
and then put it a QByteArray
if current buffer is same as old buffer it retruns 0 othewise a non-zero value.
My Problem is: It runs properly and qDebug()
prints buffer for few minutes. and then suddenly it stops. The whole Window freezes. and My application crashes. I don't think its due to memory leak. I delete
ed whenever I called new
and this is the only mutex in the whole app. Task Manager says it doesn't makes Huge Mem Use
However while Freezing it takes Huge CPU
I don't know Why I cant debug this app. It says Application Started in debug Window. Its Its not started actually. and I dont see my threads in the thread drop down box ...
EDIT
int DGRect::scan(){
HDC hdc=GetWindowDC(NULL);
HWND win=WindowFromDC(hdc);
HDC cdc=CreateCompatibleDC(hdc);
HBITMAP temp=CreateCompatibleBitmap(hdc,width,height);
PAINTSTRUCT ps;
hdc=BeginPaint(win,&ps);
HBITMAP oldb=(HBITMAP)SelectObject(cdc,temp);
BitBlt(cdc,0,0,width,height,hdc,top,left,SRCCOPY);
SelectObject(cdc,oldb);
EndPaint(win,&ps);
char* buff;
buff = new char[size()];
GetBitmapBits(temp,size(),buff);
QByteArray returnBuff(buff, size());
if(returnBuff != buffer){
buffer.clear();
buffer = returnBuff;
delete[] buff;
qDebug() << ">> \t\t\t\t UnMatched";
return 1;
}
delete[] buff;
qDebug() << ">> \t\t\t\t\t\t MATCHED";
return 0;
}
QByteArray DGRect::serialize() const{
QByteArray buff;
QTextStream stream(&buff, QIODevice::ReadWrite);
stream << row << col << left << top;
//stream << buffer;
//stream << qCompress(buffer, 8).toBase64();
stream.flush();
return QByteArray::number(row)+" "+QByteArray::number(col)+" "+QByteArray::number(left)+" "+QByteArray::number(top)+" "+QByteArray::number(buffer.size())+";";
return buff;
}
精彩评论