draco1023 / aforge

Automatically exported from code.google.com/p/aforge
Other
0 stars 0 forks source link

AccessViolationException when PictureBox displaying 16bpc image #227

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Set PictureBox.Image to a 16bpc (e.g. 48bpp RGB) image on a computer running 
64-bit OS with enough virtual memory that pointers will allocated above 2GB 
boundary.

What is the expected output? What do you see instead?
PictureBox.ConvertImage() should convert 16bpc to 8bpc and display image. 
Instead AccessViolationException occurs ("Attempted to read or write protected 
memory. This is often an indication that other memory is corrupt.")

What version of the product are you using?
2.1.5.x

Please provide any additional information below.
sourceBasePtr sourceData.Scan0.ToPointer() is of type void* but it is being 
converted to int, causing pointers above 2GB to have an undefined result.

This is the workaround I'm using.

            unsafe
            {
                // base pointers
                ushort* sourceBasePtr = (ushort*)sourceData.Scan0.ToPointer();
                byte* newBasePtr = (byte*) newData.Scan0.ToPointer( );
                // image strides
                long sourceStride = sourceData.Stride;
                long newStride    = newData.Stride;

                for ( int y = 0; y < height; y++ )
                {
                    ushort* sourcePtr = sourceBasePtr + (y*sourceStride/sizeof (ushort));
                    byte* newPtr = newBasePtr + (y*newStride/sizeof (byte));

                    for ( int x = 0, lineSize = width * layers; x < lineSize; x++, sourcePtr++, newPtr++ )
                    {
                        var c = (byte)(*sourcePtr >> 8);
                        *newPtr = c;
                    }
                }
            }

Original issue reported on code.google.com by yvan.rod...@gmail.com on 20 Jun 2011 at 2:01

GoogleCodeExporter commented 9 years ago
This may also affect AForge.Imaging.Image.Convert16bppTo8bpp()

Original comment by yvan.rod...@gmail.com on 20 Jun 2011 at 2:19

GoogleCodeExporter commented 9 years ago

Original comment by andrew.k...@gmail.com on 20 Jun 2011 at 2:43

GoogleCodeExporter commented 9 years ago

Original comment by andrew.k...@gmail.com on 20 Jun 2011 at 2:43

GoogleCodeExporter commented 9 years ago
Avoiding casting of IntPtr.ToPointer() to (int), which causes issues on 64 bit 
systems. Instead of it is casted to (byte*).

Committed in revision 1530. Will be released in version 2.2.0.

Original comment by andrew.k...@gmail.com on 21 Jun 2011 at 9:05

GoogleCodeExporter commented 9 years ago

Original comment by andrew.k...@gmail.com on 28 Jul 2011 at 9:49

GoogleCodeExporter commented 9 years ago

Original comment by andrew.k...@gmail.com on 10 Aug 2011 at 9:38