|
-
Jan 20th, 2010, 10:23 PM
#1
Thread Starter
Stack Overflow moderator
[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:
Private Sub LoadNextBitmap() Try If m_Deserializer.PeekChar() = -1 Then Exit Sub Catch ex As Exception End Try m_CurBitmap = New Bitmap(w, h, PixelFormat.Format24bppRgb) Dim bpbmp As Integer = w * h * 3 Dim bdata As BitmapData = m_CurBitmap.LockBits(New Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb) ' ^ I've also tried ImageLockMode.ReadOnly, no success. Dim b(bpbmp - 1) As Integer For i As Integer = 0 To bpbmp - 1 b(i) = m_Deserializer.ReadByte() Next Marshal.Copy(b, 0, bdata.Scan0, bpbmp) '<-- error here m_CurBitmap.UnlockBits(bdata) 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.
-
Jan 21st, 2010, 09:56 AM
#2
Thread Starter
Stack Overflow moderator
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.
-
Jan 21st, 2010, 10:09 AM
#3
Thread Starter
Stack Overflow moderator
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|