![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Originally posted this questionhttp://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2444877&SiteID=1but realized it was the wrong forum. These two examples might be bugs, missing documentation or me being silly. This code bit generates an OverflowException. Graphics g = this.CreateGraphics(); Point [] points = new Point[] {new Point(0,0), new Point(878,1074000000)}; using (Pen pen = new Pen(Color.Black)) { g.DrawLines(pen, points); } It appears that somewhere between 1,073,000,000 and 1,074,000,000 there is a limitation that leads to the exception. Can someone please verify this? Obviously this is huge number and not a big deal (for me anyway). But I thought maybe the fact that the method can throw such an exception and maybe the limit should be mentioned in the docs (http://msdn2.microsoft.com/en-us/library/7ewkcdb3.aspx) This code bit generates an OutOfMemoryException. Graphics g = this.CreateGraphics(); Point [] points = new Point[] {new Point(0,0), new Point(64,60000000)}; using (Pen pen = new Pen(Color.Black)) { pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; pen.DashOffset = 1; g.DrawLines(pen, points); } Dont know the source of this problem. Same points as above apply. Appreciate any help. |
#3
| |||
| |||
|
|
Hi, Using GDI+ as you are in C# you really must make sure your geometry is within the bounds of your window/graphics. Rendering very large lines, polygons or even very small ones, e.g. where essentially you render a line on a single pixel can lead to this kind of errors. I always assumed GDI+ would perform some sort of intelligent clipping, but it doesn't. The underlying draw line routines just really seem t try to render a line, hence it might take a long time. So either wrap it into a try..catch or perform some clipping of your own...or perhaps better move to WPF. Cheers, Patrick On Nov 22, 4:23 pm, RedLars <RedL... (AT) discussions (DOT) microsoft.com> wrote: Originally posted this questionhttp://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2444877&SiteID=1but realized it was the wrong forum. These two examples might be bugs, missing documentation or me being silly. This code bit generates an OverflowException. Graphics g = this.CreateGraphics(); Point [] points = new Point[] {new Point(0,0), new Point(878,1074000000)}; using (Pen pen = new Pen(Color.Black)) { g.DrawLines(pen, points); } It appears that somewhere between 1,073,000,000 and 1,074,000,000 there is a limitation that leads to the exception. Can someone please verify this? Obviously this is huge number and not a big deal (for me anyway). But I thought maybe the fact that the method can throw such an exception and maybe the limit should be mentioned in the docs (http://msdn2.microsoft.com/en-us/library/7ewkcdb3.aspx) This code bit generates an OutOfMemoryException. Graphics g = this.CreateGraphics(); Point [] points = new Point[] {new Point(0,0), new Point(64,60000000)}; using (Pen pen = new Pen(Color.Black)) { pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; pen.DashOffset = 1; g.DrawLines(pen, points); } Dont know the source of this problem. Same points as above apply. Appreciate any help. |
#4
| |||
| |||
|
|
Thanks for your prompt reply. In my opinion the OverflowException and limit should be added as a comment to the MSDN doc's for the relevant api. Did some future research into the OutOfMemoryException. While using the following code (see below) the points array can contain any value upto +_ 1,073,000,000 which is fine. Graphics g = this.CreateGraphics(); using (Pen pen = new Pen(Color.Black)) { pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; g.DrawLines(pen, points); } However, by using DashStyle.Dot it appear (on my computer) that values of excess of 53 000 000 will cause an OutOfMemoryException. When using DashStyle.Dash the limit seems to be around 89 000 000 and with DashStyle.DashDot it is apporximately 66 000 000. Are these limits hardware (amount of memory on computer) related or driver\software releated, or a fixed limit set my microsoft for each style? Obviously these kinds of values should not happen but under very rare circumstances we have encountered this problem. What would be a safe value to replace a value that in todays system lead to an exception? (There might be one or two points in the array that are corrupt\extremly high, and the rest are valid - hence we want to draw the line even with some fault data). Regards, RedLars "Patrick van Dijk" wrote: Hi, Using GDI+ as you are in C# you really must make sure your geometry is within the bounds of your window/graphics. Rendering very large lines, polygons or even very small ones, e.g. where essentially you render a line on a single pixel can lead to this kind of errors. I always assumed GDI+ would perform some sort of intelligent clipping, but it doesn't. The underlying draw line routines just really seem t try to render a line, hence it might take a long time. So either wrap it into a try..catch or perform some clipping of your own...or perhaps better move to WPF. Cheers, Patrick On Nov 22, 4:23 pm, RedLars <RedL... (AT) discussions (DOT) microsoft.com> wrote: Originally posted this questionhttp://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2444877&SiteID=... realized it was the wrong forum. These two examples might be bugs, missing documentation or me being silly. This code bit generates an OverflowException. Graphics g = this.CreateGraphics(); Point [] points = new Point[] {new Point(0,0), new Point(878,1074000000)}; using (Pen pen = new Pen(Color.Black)) { g.DrawLines(pen, points); } It appears that somewhere between 1,073,000,000 and 1,074,000,000 there is a limitation that leads to the exception. Can someone please verify this? Obviously this is huge number and not a big deal (for me anyway). But I thought maybe the fact that the method can throw such an exception and maybe the limit should be mentioned in the docs (http://msdn2.microsoft.com/en-us/library/7ewkcdb3.aspx) This code bit generates an OutOfMemoryException. Graphics g = this.CreateGraphics(); Point [] points = new Point[] {new Point(0,0), new Point(64,60000000)}; using (Pen pen = new Pen(Color.Black)) { pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; pen.DashOffset = 1; g.DrawLines(pen, points); } Dont know the source of this problem. Same points as above apply. Appreciate any help. |
#5
| |||
| |||
|
|
Originally posted this question http://forums.microsoft.com/MSDN/Sho...44877&SiteID=1 but realized it was the wrong forum. These two examples might be bugs, missing documentation or me being silly. This code bit generates an OverflowException. Graphics g = this.CreateGraphics(); Point [] points = new Point[] {new Point(0,0), new Point(878,1074000000)}; using (Pen pen = new Pen(Color.Black)) { g.DrawLines(pen, points); } It appears that somewhere between 1,073,000,000 and 1,074,000,000 there is a limitation that leads to the exception. Can someone please verify this? Obviously this is huge number and not a big deal (for me anyway). But I thought maybe the fact that the method can throw such an exception and maybe the limit should be mentioned in the docs (http://msdn2.microsoft.com/en-us/library/7ewkcdb3.aspx) This code bit generates an OutOfMemoryException. Graphics g = this.CreateGraphics(); Point [] points = new Point[] {new Point(0,0), new Point(64,60000000)}; using (Pen pen = new Pen(Color.Black)) { pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; pen.DashOffset = 1; g.DrawLines(pen, points); } Dont know the source of this problem. Same points as above apply. Appreciate any help. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |