Attempted to read or write protected memory.

2009-10-29
2012-10-29
  • dheeraj mittal

    dheeraj mittal - 2009-10-29

    Hi,

    I have this error in "CopyMemory".
    Attempted to read or write protected memory. This is often an indication that
    other memory is corrupt.

    region API

    private static extern void CopyMemory(IntPtr Destination, IntPtr Source, uint
    Length);

    endregion

    IntPtr ipSource = m_bmdLogo.Scan0;
    IntPtr ipDest = (IntPtr)(pBuffer.ToInt32() + ((w * 3) * N));

    CopyMemory(ipDest, ipSource, ((uint)m_bmdLogo.Stride));

    please help regarding this issue

    Thanks !
    dhemittal@gmail.com

     
  • Eric

    Eric - 2009-10-29

    The CopyMemory P/Invoke declaration is correct so the problem don't come from
    that.

    Assuming that the BitmapData object point to a locked bitmap data, the memory
    access problem can't come from the source part.

    So the problem is the destination part. Put some breakpoints in your code and
    check if the computed value is correct. The ipDest calculation is not 64 bits
    friendly. Use ToInt64 instead. This will works for both system kind. You can
    also make this calculation with some pointer arithmetic (void* can explicitly
    be casted to IntPtr).

     
  • snarfle

    snarfle - 2009-10-29

    This looks like a very simple debugging issue. Just because you are using
    DirectShow doesn't mean you should forget everything you ever learned about
    how to debug code.

    Try adding this just before the CopyMemory call:

    Debug.WriteLine("{0} {1} {2}", ipDest.ToInt32(), ipSource.ToInt32(),
    ((uint)m_bmdLogo.Stride));

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks