I am working on a camera to collect data. In the process one of the functions is throwing errors while copying the data from the buffer on board to local system buffer.
The message which I am getting is
Unhandled exception at 0x1026ef58 (msvcr90d.dll) in Camera.exe: 0xC0000005: Access violation reading location 0xd41dddcc.
Code:
__declspec(dllexport) int intf_daq_get_frame (void * intf_p, unsigned char * frame_data, unsigned long frame_size)
{
BFDev *bf_p;
bf_p = (BFDev *) intf_p;
if (bf_p == NULL)
{
return FAILURE;
}
// Wait for frame to be acquired.
bf_p->rv = BiCirWaitDoneFrame(bf_p->Board, &bf_p->BufArray, INFINITE, &bf_p->CirHandle);
// Process newly acquired frame
memcpy(frame_data, (unsigned char *) (bf_p->CirHandle.pBufData), frame_size);
// Mark the processed buffer available for acquisition
bf_p->rv = BiCirStatusSet(bf_p->Board, &bf_p->BufArray, bf_p->CirHandle, BIAVAILABLE);
if(bf_p->rv != BI_OK)
{
BiErrorShow(bf_p->Board, bf_p->rv);
return FAILURE;
}
return SUCCESS;
}
Can someone tell me what would have went wrong and any suggestions.
I know nothing about cameras and stuff, but if you are sure that the memcpy is the failure, then I have to assume that 'bf_p->CirHandle.pBufData' is not valid. So, or 'bf_p' is not valid or 'pbBufData' is not valid. You can use the debugger to inspect bot pointers and see what they contain.
Casts are pure evil when used (without a deep understanding) just to solve a compiler error and I think this shows that you are in deep water at the moment
I would advise you to get rid of all casts and solve the compilation issues by using the correct types instead.
Last edited by S_M_A; April 22nd, 2010 at 04:35 PM.
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
And how would you like to do that if 'bf_p->CirHandle.pBufData' is a void* that actually points to a byte buffer ?
memcpy is declared like
Code:
void* memcpy(void* dst, void* src, size_t size);
which is to say it accepts any pointer for the params so why should it be any problem to use a pointer to the correct type? The cast in the call to memcpy just tells the compiler: "ignore that this looks strange, I know what I'm doing"
So, if pBufData actually points at a byte buffer I prefer to declare it as an unsigned char* to help the compiler help me in finding my mistakes.
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
Bookmarks