Graphic out-of-memory exception.

newguy

Well-known member
Joined
Jun 30, 2008
Messages
611
Location
Denver Co, USA
Programming Experience
1-3
I am new to graphics, I am playing with the GraphicsPath. It was working fine, but now it gives me the above exception after drawing 1 figure.
VB.NET:
'Mouse Down
mousePath.StartFigure()

'Mouse Move
mousePath.AddLine(e.X, e.Y, e.X, e.Y)
pb1.Invalidate()

'Paint event
Dim draw_pen As New Pen(Color.Navy, 2)
e.Graphics.DrawPath(draw_pen, mousePath)
draw_pen.Dispose()

I even used Using/End Using same problem. This is based on an example I found.
 
Ok, it works fine in a Try/Catch. Any things to worry about or is this how it is supposed to be used?
 
Using Try/Catch just to suppress an error message isn't a good idea. It tends to disguise the problem instead of solving it, so even if the program seems to work there may be trouble ahead.

I can't see anything in what you posted that could cause the error, so maybe you need to post the actual code. Please say if you know which line throws the exception.

There's nothing wrong with Using/End Using or Dim/Dispose for the pen. Personally I think Using looks neater, and in some situations it is more reliable (for example it closes a file before disposing it).

cheers, Vic
 
Well that's what I thought too, but it too was in the example. I will go thru it again, but all the drawing object where being disposed as well as this one. There are some other drawing objects depending on the enum selected. Worse comes to worst I will post it all. Thanks...
 
Back
Top