cart: empty [ Login ]

GraphicHelper is disposable... wait! Is it?

1 
Palver123
4/1/2019 7:09 PM
Hi! I have been fiddling around with one of your samples: WinFormsExtendedViewExample I have noticed that the view control contains a disposable member: graphicsHelper. I was sad to see that disposing it throws an ArgumentException:
Changes cannot be made to Brush because permissions are not valid.
After a bit of thinking I figured out the reason. GraphicsHelper constructor initializes the backing fields of DefaultPen and DottedPen to newly created pen objects. The backing field of HighlightPen however stay at its default value: Pens.Green. This is an immutable system pen and thus, non-disposable. Trying to dispose it will throw the above mentioned exception. Am I right in saying that this is a bug? I can temporarily fix this by overriding all the system pens/brushes/fonts used in GraphicsHelper before disposing it, but it's a sloppy workaround. I am using CadLib version 4.0.38.118
Wout
4/1/2019 8:26 PM
Good catch, I've updated the release and trial versions. Pity you can't check if a Pen/Brush is immutable, so now the code calls Dispose() and just catches the ArgumentException. - Wout
Palver123
4/2/2019 10:17 AM
Thanks! Will check!
1