I am writing a VirtualDub filter, which requires a separate frame buffer for intermediate image processing between fa->src.data and fa->dst.data (.data is essentially a pointer to Pixel data).
I create a char pointer to the above using this:
/* Pointers to source and destination frame stores */
char *src = (char *)fa->src.data;
char *dst = (char *)fa->dst.data;
/* Image width and height */
int w = fa->src.w*sizeof(Pixel32);
int h = fa->src.h*sizeof(Pixel32);
This then allows me to copy data from source frame to destination frame, line by line:
memcpy(dst,src,w);
Now I would like to have an intermediate buffer that I can copy from *dst to buffer, then from buffer to *src. How can I do that?
I tried several things with varying degrees of success.
/* Define and initialise char array with malloc */
char *buf = (char*)malloc(w*h);
Then:
memcpy(buf,src,w); /* copy to buffer */
memcpy(dst,buf,w); /* copy from buffer to dst */
Most of the time, this seems to work. However, after a short while I get "An out-of-bounds memory access (access violation) occurred in module ". The issue is that I seem to run out of system memory (VirtualDub takes ALL the available memory after a while).
Do I need to free the buffer? Seems odd, since it is initialised every frame. How can I free it?
I tried free(dstbuf) and free(&dstbuf) but I am getting "Debug Assertion Failed" error at runtime, expression: _CrtIsValidHeapPointer(pUserData)... with not much else.
Any ideas?