472,958 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

Graphics.DrawPolygon with Custom Dash throws Exception

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
3 3887
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Blake T. Garretson | last post by:
I'm having some issues with decimal.Decimal objects playing nice with custom data types. I have my own matrix and rational classes which implement __add__ and __radd__. They know what to do with...
0
by: Aaron Randolph | last post by:
I just ran into a weird problem. I have an application that parses an XML document using SAX with MSXML. When it finds a certain field, it throws a custom exception derived from Exception called...
7
by: Ken Allen | last post by:
I have a .net client/server application using remoting, and I cannot get the custom exception class to pass from the server to the client. The custom exception is derived from ApplicationException...
0
by: Chua Wen Ching | last post by:
Hi there, I had been wondering for a while. I am building a very efficient Custom Exception Library. But i wasn't that sure whether i should be using XML or not. There are 3 ways which i...
2
by: yotaxp | last post by:
Hello, all. This line has been pestering me, and I can't seem to figure out why the problem is occuring. I'm trying to paint a GraphicsPath onto a Bitmap, using the Graphics class, but it...
0
by: Søren Lund | last post by:
Hello, I have implemented a custom config section handler by implementing the IConfigurationSectionHandler interface. I have registered this handler in web.config and everything works fine ......
1
by: leodippolito | last post by:
Dear sirs, I am using custom wrappers to primitive types in my classes, so I can have some flags when working with the database ("undefined" and "null") .. So instead of: public class...
5
by: iainfogg | last post by:
I had an ASP.NET 2.0 site which works fine on my PC. I have just copied it to a server, and set it up to run in a virtual folder. The web pages work fine, but the graphics won't load - if I try to...
0
by: Hasim AH | last post by:
Hi .. Just getting interested to learn C# and needs help. I want to write C# application so that the program will execute and draw graphics when the user select the drawing menu from the main...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.