0

I'm Using VisualStudio 2010 and MFC, And using Allied Visinon Vimba API to get Asynchronousgrab image. Variable m_Image is filled with data that grabbed image from Camera, And updated whenever camera sends the new grab image.

I tried to copy CImage Variable (m_Image) to another Variable (local_img). And 0xC0000005 exception error occured.

Here is my CPP file Function

void CTestDlg::OnBnClickedCopy()
{
    CImage local_img;
    header_image = m_Image; // no error
    local_img = m_Image;  // error
}

Here is my Header declaration part.

class CTestDlg : public CDialogEx
{
private
    CImage m_Image;
    CImage header_image;
}

I want to know why the exception error occured when I try to copy variable that declared at header to variable that declared as local.

It may be the problem that I didn't understand the how to use API well

  • Please take the [tour] and read [ask]. Specifically, make sure to show a [mcve], including the complete, unabridged error diagnostic. An access violation can happen for any number of reasons. Telling us that you're getting a `0xC0000005` exception isn't very useful. – IInspectable May 11 '22 at 10:09
  • You have exception because when you do **local_image = m_Image;** your local_image variable takes probably a reference of a pointer from m_image and continue to us it even if this last was deleted. So you will manipulate a memory adress wich are no more available. i don’t know this image class/struct, they are probably some function to copy/clone an image properly. – Landstalker May 11 '22 at 11:59
  • Does this answer your question? [How to copy a CImage object?](https://stackoverflow.com/questions/9571304/how-to-copy-a-cimage-object) – Andrew Truckle May 11 '22 at 17:43

1 Answers1

0

The main reason is the lack of "copy constructor" in CImage class. you shouldn't copy an object like that.

  • 1
    [Reviewed as first answer] It would be useful to show the correct way to copy CImage, not just say the OP's approach is wrong. – Sarah Phillips May 17 '23 at 23:52