1

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?

Vitor Py
  • 5,145
  • 4
  • 39
  • 62

1 Answers1

2

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

dario_ramos
  • 7,118
  • 9
  • 61
  • 108
  • Dario, thank you. Actually had I unsigned int that overflowed after being subtracted by a signed value greater than itself, feeding garbage data to StretchBlt. You said about leaks and I took a long look in the code and found it. Thank you! – Vitor Py Aug 23 '11 at 16:39