By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,978 Members | 1,361 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,978 IT Pros & Developers. It's quick & easy.

Graphics.DrawPolygon with Custom Dash throws Exception

P: n/a
Hi.

I have a problem. When drawing into a graphics context I sometimes get
access violation exceptions and I can't figure out why. It seems to
have to do with the use of custom dashes. If I change the dash I get
the exception. Following is a code example:

Pen pLine = new Pen(colBkg); // colBkg is a valid color

// fill area with background color. g is a valid graphics context
g.FillRectangle(pLine.Brush, rectArea);

// draw line
pLine.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
pLine.DashPattern = new float[] { 1.0f, 30.0f};
pLine.Width = 5.0f;
g.FillPolygon(pLine.Brush, points); // points is a Point Array with
valid points

This works as it's supposed to. But if I change the line where I
define the dash, it throws the exception:

pLine.DashPattern = new float[] { 1.0f, 30.0f, 1.0f}; // -Exception

I know, it's hard to see an error here with so little code.. But it's
only the pattern that causes the Exception. And it only happens with
certain values.. I thought maybe somebody already encountered similar
problems and can give me a hint. Thank you in advance.

Sebastian M. Rouaiha

Feb 5 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I have a problem. When drawing into a graphics context I sometimes get
access violation exceptions and I can't figure out why. It seems to
have to do with the use of custom dashes.
All of the GDI+ functions will throw an OutOfMemoryException with
various configurations that make them draw really small objects. Just
catch the exception and ignore it. It becomes even more evident with
transforms.

I personally think it's a bug, but from the feedback I gave to MS it
seems that nobody cares. I think they should because the extra try/
catch just slows things down.

Another strange bug is that, though the width of the pen is changed by
a transform, the spacing in the dash pattern is not. It's obvious then
that the dash pattern had no QA. I'm not surprised that it causes
other errors.

Feb 5 '07 #2

P: n/a
On 5 Feb., 17:37, "not_a_commie" <notacom...@gmail.comwrote:
All of the GDI+ functions will throw an OutOfMemoryException with
various configurations that make them draw really small objects. Just
catch the exception and ignore it. It becomes even more evident with
transforms.
It's an Access Violation Exception and I can't catch it. Of course I
tried to just put a try/catch block around the draw calls (whole
function or just the draw call, didn't matter). Sometimes I was able
to catch the Exception, but sometimes it just occured anywhere. It's
very strange.. I already thought maybe I had some errors that would
lead to this behaviour, but I was able to break it down to the pattern
stuff. I already started to write my own drawing functions (especially
since I don't want the pattern/dash to be depending on the line's
width).
Another strange bug is that, though the width of the pen is changed by
a transform, the spacing in the dash pattern is not. It's obvious then
that the dash pattern had no QA. I'm not surprised that it causes
other errors.
Which transformation are you referring to? The draw call accepts pixel
coordinates - which transformation would be necessary that changes the
width?

rou

Feb 6 '07 #3

P: n/a
Which transformation are you referring to? The draw call accepts pixel
coordinates - which transformation would be necessary that changes the
width?
The transformation I was referring to was the Transform member of the
Graphics class. The draw calls accept floating point as well as
integer pixel coordinates. However if you give it a transform, the
coordinates are no longer relative to pixels. Look up 2D graphics
transforms and matrices online to see what I mean.

Feb 6 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.