1
Vote

AAWidthLine IndexOutOfRange

description

WriteableBitmapEx Version 1.5.0, WinRT Windows running on W10

The following code produces IndexOutOfRangeException
bitmap extent [w=1737, h=3855], color is black FF000000
        int height = context.Bitmap.PixelHeight; // = 1737
        int width = context.Bitmap.PixelWidth; // = 3855
!==> context.Bitmap.DrawLineAa(0, height - 1, width / 2, height - 1, color, 2);

at Windows.UI.Xaml.Media.Imaging.WriteableBitmapExtensions.AAWidthLine(Int32 width, Int32 height, BitmapContext context, Single x1, Single y1, Single x2, Single y2, Single lineWidth, Int32 color)
at Windows.UI.Xaml.Media.Imaging.WriteableBitmapExtensions.DrawLineAa(WriteableBitmap bmp, Int32 x1, Int32 y1, Int32 x2, Int32 y2, Color color, Int32 strokeThickness)

comments

teichgraf wrote Nov 11, 2015 at 1:34 PM

Thanks for pointing this out. Can you also repro it with a different size like 1738 x 3856?
Also, it would be helpful and increase the chance of a faster resolve if you attach a sample sln.

mneumann wrote Apr 18, 2016 at 3:41 PM

I've reproduced it with the following parameter / call:
DrawLineAa(WriteableBitmap(W:2000 x H:1324), 304, 1324, 225, 1324, #FF0000FF, 5)

I see that the y1, y2 are outside the bitmap. However, I expect the line to be properly clipped
or as the second best solution an informative exception to be thrown.
Without source code I was only guessing and never came behind the cause.
Method AADrawLine()
{
...
   if (y1 == y2)
   {
   ...
     // x = 225
     // y = 1324
     // w = 2000
     // buffer.Length = 2648000
     // y * width + x = 2648225
     // it looks like it goes one line down outside of the bitmap
      d = buffer[y * width + x]; // crash here
   }
}