StretchBlt fails

377 Views Asked by At

I have a COM component. This COM components shows an image on the screen. The image bits are copied through a buffer like this:

IplImage iplimage = image;

IplImage *img2 = cvCreateImage(cvGetSize(&iplimage),
                           iplimage.depth,
                           iplimage.nChannels);

cvCopy(&iplimage, img2);

memcpy(m_BackSurface.vpBits, img2->imageData, img2->width*img2->height*3);

Where image is a cv::Mat. On certain conditions this is a cropped cv::Mat, ie. the return of the raw_image(x0, y0, w, h) where raw_image is another cv::Mat.

Later the application calls StretchBlt to show the image.

If I'm running this COM component inside a .NET application (and only when inside a .NET application this doesn't occurs on a pure unmanaged environment) the call to StretchBlt fails when (again, only when) image has been cropped. It does not fail on the code path where image isn't cropped. The drawing code is the same for both code paths. GetLastError() will return the error 8.

Can someone shed a light on this issue?

1

There are 1 best solutions below

1
On

Error code 8, according to MSDN, corresponds to ERROR_NOT_ENOUGH_MEMORY. Now that you're running in a .NET environment, you have less available memory since the CLR is loaded into your process. You should try to reduce memory usage, and look for memory leaks as well