Bug 1202 - Graphics.DrawLine draws line when NaN is supplied.
Summary: Graphics.DrawLine draws line when NaN is supplied.
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: libgdiplus ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-10-03 14:37 UTC by eylvisaker
Modified: 2012-06-25 06:37 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 1202 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description eylvisaker 2011-10-03 14:37:35 UTC
The Graphics.DrawLine method will draw a line when NaN is supplied as one of the point arguments. The Microsoft implementation will skip drawing the line.

Sample code which reproduces the bug:
[code]
using System;
using System.Drawing;
using System.Windows.Forms;

class Form1 : Form
{
    public static void Main()
    {
        Application.Run(new Form1());
    }

    PictureBox box;

    Form1()
    {
        box = new PictureBox();
        box.Dock = DockStyle.Fill;

        this.Controls.Add(box);

        Bitmap image = new Bitmap(100, 100);
        Graphics g = Graphics.FromImage(image);

        g.DrawLine(Pens.Black, float.NaN, float.NaN, 100, 100);
        g.Dispose();

        box.Image = image;

    }
}
[/code]

On Windows this should draw nothing. On Linux I see a diagonal line.
Comment 1 Robert Wilkens 2012-06-23 09:23:45 UTC
I created a patch so it does not draw a diagonal line with the sample code provided, there may be more places NaN should be checked, but i did not want to attempt to fix everything that could possibly be wrong while working on one bug
report.

The pull request including the patch is here, there is no guarantee it will be included
https://github.com/mono/mono/pull/344 

In my testing, i verified that the red lines (in revised sample code below) ARE drawn, and the black line is not drawn.  IF this is an issue with other variants of DrawLine, please file another bug report with those details if you haven't already.

using System;
using System.Drawing;
using System.Windows.Forms;

class Form1 : Form
{
    public static void Main()
    {
        Application.Run(new Form1());
    }

    PictureBox box;

    Form1()
    {
        box = new PictureBox();
        box.Dock = DockStyle.Fill;

        this.Controls.Add(box);

        Bitmap image = new Bitmap(100, 100);
        Graphics g = Graphics.FromImage(image);

        g.DrawLine(Pens.Red, 0.0F, 100.0F, 100.0F, 0.0F);
        g.DrawLine(Pens.Black, float.NaN, float.NaN, 100, 100);
        g.DrawLine(Pens.Red, 0, 50, 100, 50);

        g.Dispose();
        box.Image = image;

    }
}
Comment 2 Robert Wilkens 2012-06-23 10:32:27 UTC
Ok, This fix has been merged into the master branch of mono on github from what i can see (this will not reach you right away, unless you are building mono from the latest github source).  It can probably be closed, but i do not have that authority.
Comment 3 Robert Wilkens 2012-06-25 06:37:27 UTC
https://github.com/mono/mono/pull/344 was the related pull request that was merged.  I just wanted to note that here in case anyone had any questions.