|
Project projectname raised too many consecutive exceptions :
access violation at 0xfffef88f : read of address 0xfffef87f :
Process Stopped.Use step or Run to continue;
에러가 뜹니다 디버깅도 안되고
예상되는 부분 모두 break point 잡아도 안됩니다.
어떻게 하면 좋을까여?
밑의 소스는 시리얼로 데이타를 보내는 소스입니다.
WriteData함수를 이용하여 1500바이트 정도의 데이타를 보냅니다.
void __fastcall TFileWriteThread::WriteData(BYTE* s)
{
DWORD ErrCode;
::EnterCriticalSection(&CriticalSection);
int len = 2048;
memcpy(WriteString,&s,len); -->WriteString에 데이타를 저장합니다.
::LeaveCriticalSection(&CriticalSection);
SetEvent(osWrite.hEvent);
}
bool TFileWriteThread::WriteCommBlock(unsigned char *lpByte , int dwBytesToWrite)
{
.....
fWriteStat = ::WriteFile( hWrite, lpByte, dwBytesToWrite, &dwBytesWritten, &osWrite ) ;
if(!fWriteStat) {
if(::GetLastError() == ERROR_IO_PENDING) {
while(!GetOverlappedResult(hWrite,&osWrite,&dwBytesWritten,TRUE)) { ------1번 위치
if(GetLastError() == ERROR_IO_INCOMPLETE) {
dwBytesSent += dwBytesWritten;
continue;
}
else {
::ClearCommError(hWrite,&dwError,&comstat);
break;
}
}
dwBytesSent += dwBytesWritten;
if(dwBytesSent != dwBytesToWrite)
wsprintf(szError,"Probable Write Timeout: Total of %ld bytes sent", dwBytesSent);
else wsprintf(szError,"%ld bytes written", dwBytesSent);
}
else {
::ClearCommError(hWrite,&dwError,&comstat);
return false;
}
}
return true;
}
//Main loop
void __fastcall TFileWriteThread::Execute(void) ///-->WriteThread를 시작합니다.
{
DWORD BytesWritten, ErrCode;
AnsiString a;
while (!Terminated)
{
if (WriteString[0] != 0x00)
{
memset(Buffer, '\0', sizeof(Buffer));
EnterCriticalSection(&CriticalSection);
memcpy(Buffer, &WriteString, sizeof(char)*2048);
WriteString[0] = 0x00;
LeaveCriticalSection(&CriticalSection);
int a = 1500;
if (!WriteCommBlock(Buffer, a)) //-->WriteCommBlock 함수를 호출합니다.
if ((ErrCode = GetLastError()) != ERROR_IO_PENDING)
ShowMessage("Error on write file " + IntToStr(ErrCode));
}
DWORD aaa = ::WaitForSingleObjectEx(osWrite.hEvent, INFINITE, TRUE);
}
위의 1번 위치에서 처음 데이타를 보낼때는 잘 동작하지만
2번째 1500바이트를 보내면 CPU의 사용이 갑자기 커지면서
프로그램이 동작하지 않고 조금 더 있으면 맨위의 에러 메세지가 뜹니다.
어느 부분이 잘못됐는지 잘 모르겠습니다.
동작상에는 문제가 없어 보이는데..
|