I am writing a video program, everything works fine except I am often (ie most times, but not every time) getting the following error:
Unhandled exception at 0x6076fde0 (msvcr90d.dll) in javaw.exe: 0xC0000005: Access violation reading location 0x0a450020.
I have tracked it down to this function:
//fill the buffer from data
void TFrame::WriteBuffer(unsigned char *ucBuffer){
if (PixelBuffer != NULL)
{
if ( ucBuffer != NULL)
{
if (PixelBufferSize != NULL)
{
//the error doesnt occour when this line is commented out
memcpy (PixelBuffer,ucBuffer,PixelBufferSize);
}
}
}
}
I start a thread to capture the video. The exception only happens when I am ending it. This is the "run" method:
void TImageProcessor::run()
{
//only perform action when CapturingVideo is true;
TerminatedThread=false;
while(true){
if (capturingVideo)
{
unsigned char * ret = StillCapture->GrabImage();
Frame->WriteBuffer( ret );
//the following line is where the exception occours vvv
Sleep(20);
} else {
// checks it isnt needed ~ 50 times a second
Sleep(20);
}
if (TerminatedThread)
{
break;
}
}
cout << "ending thread" << endl;
}
I really have no idea why a memcpy would fail like this! At first I thought that some of the variables were null or something, I am used to programming in Java, so I dont have a whole lot of experience with pointers, so I am not sure my null checks are right.
Thanks for any help