Results 1 to 3 of 3

Thread: [RESOLVED] Reading/Writing protected memory - no idea how to debug

  1. #1

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Resolved [RESOLVED] Reading/Writing protected memory - no idea how to debug

    I've made a screen capture program, and I have a program to play back the captured clips (right now there's no sound). All of the data is stored like so:

    Frames per second, as a Byte
    Width of each bitmap, as an Integer
    Height of each bitmap, as an Integer
    All of the bitmaps' data (24 bits per pixel)

    In the playback form, I have a function to read the next bitmap from the file, using the stored width and height:
    vb.net Code:
    1. Private Sub LoadNextBitmap()
    2.         Try
    3.             If m_Deserializer.PeekChar() = -1 Then Exit Sub
    4.         Catch ex As Exception
    5.  
    6.         End Try
    7.         m_CurBitmap = New Bitmap(w, h, PixelFormat.Format24bppRgb)
    8.         Dim bpbmp As Integer = w * h * 3
    9.         Dim bdata As BitmapData = m_CurBitmap.LockBits(New Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb)
    10.         ' ^ I've also tried ImageLockMode.ReadOnly, no success.
    11.         Dim b(bpbmp - 1) As Integer
    12.         For i As Integer = 0 To bpbmp - 1
    13.             b(i) = m_Deserializer.ReadByte()
    14.         Next
    15.         Marshal.Copy(b, 0, bdata.Scan0, bpbmp) '<-- error here
    16.         m_CurBitmap.UnlockBits(bdata)
    17.     End Sub
    I get an error on the Marshal.Copy line: "AccessViolation exception was unhandled: Attempted to read or write protected memory. This is often an indication that other memory is corrupt." I suppose that this means that I'm writing too much data to the area in memory specified by the pointer, but I don't see how. The b() array seems to be in working order. Can anyone help? The file saves just fine.

  2. #2

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Reading/Writing protected memory - no idea how to debug

    I've tried all sorts of numbers instead of bpbmp, some of them give a strange and colorful result (ones that are quite a bit less than bpbmp). So I know the data isn't corrupted.

  3. #3

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Reading/Writing protected memory - no idea how to debug

    Oops... :P

    Accidentally declared the array as Integer() instead of Byte(). Never mind!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width