Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Out of memory exception (Read 6354 times)
jf2020
Junior Member
**
Offline


I love FlowChart!

Posts: 63
Joined: Feb 23rd, 2006
Out of memory exception
Mar 25th, 2013 at 9:41pm
Print Post  
Hi Stoyan,

Our users have managed to create a diagram that is very quickly throwing an out of memory exception as soon as it is zoomed out using the mouse wheel.

Here's the call stack:

Code
Select All
************** Exception Text **************
System.OutOfMemoryException: Out of memory.
   at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
   at System.Drawing.Graphics.DrawPath(Pen pen, GraphicsPath path)
   at MindFusion.Drawing.GdiGraphics.DrawPath(Pen pen, GraphicsPath path)
   at MindFusion.Diagramming.ShapeNode.DrawOutline(DrawParams dp)
   at MindFusion.Diagramming.ShapeNode.DrawShape(IGraphics graphics, RectangleF rc, Boolean shadow, Brush mfBrush, Pen mfPen, RenderOptions options)
   at MindFusion.Diagramming.ShapeNode.DrawShadow(IGraphics graphics, RenderOptions options)
   at MindFusion.Diagramming.Diagram.DrawItemWithShadow(IGraphics graphics, DiagramItem item, Boolean relatedItems)
   at MindFusion.Diagramming.Diagram.DrawItems(IGraphics graphics, RectangleF clipRect, Boolean modfBackBuf)
   at MindFusion.Diagramming.Diagram.Draw(IGraphics graphics, RenderOptions options, RectangleF clipRect, Boolean noModifiedItems)
   at MindFusion.Diagramming.WinForms.DiagramView.DrawDiagram(IGraphics graphics, RectangleF clip, Boolean noModifiedItems)
   at MindFusion.Diagramming.WinForms.DiagramView.OnPaint(PaintEventArgs pe)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
 



I know that I'm not providing a lot of info but any idea what can cause this and/or what to look for?

EDIT: Actually I can zoom without the exception as long as i want between 200% and 50% but as soon as I try to set the zoom level to 40% i get the out of memory exception.
EDIT2: Setting the zoom level to 39% or to 41% works but setting it to 40% immediately generates the exception!!
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Out of memory exception
Reply #1 - Mar 26th, 2013 at 8:21am
Print Post  
Hi,

Are you using any dashed pen styles? We used to get similar exceptions often when drawing dashed links with anti-aliasing enabled due to some GDI+ bug, and added the CatchGdiPlusExceptions property to work around that. Unfortunately the exception is caught only by the DiagramLink class at this time since it's what we had problems with in the past. We'll add checks in the node classes too if it's the same issue.

Stoyan
« Last Edit: Mar 26th, 2013 at 10:58am by Stoyo »  
Back to top
 
IP Logged
 
jf2020
Junior Member
**
Offline


I love FlowChart!

Posts: 63
Joined: Feb 23rd, 2006
Re: Out of memory exception
Reply #2 - Mar 26th, 2013 at 11:08am
Print Post  
Yes indeed it's crashing on the drawing of a node that has
Code (C++)
Select All
ShapeNode.Pen.Width = 0;
                ShapeNode.Pen.DashStyle = DashStyle.Dash; 



If I set
Code (C++)
Select All
diagramView.SmoothingMode = SmoothingMode.None; 

it no longer crashes, so its definitely what you were suggesting above. What is strange is that I have many other nodes with the same properties on this diagram and only this specific node is generating the exception. Is is something related to the size of the node?

I have also found the property CatchGdiPlusExceptions (BTW the documentation is incorrect for this property in the CHM, you may want to fix it) but as you said setting it to true doesn't fix the issue.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Out of memory exception
Reply #3 - Mar 26th, 2013 at 11:48am
Print Post  
If I remember correctly, we were getting this exception only with curved links, so I suppose it depends mostly on the border shape and coordinates, but possibly the colors of its surrounding pixels too. Our developer will implement this for nodes in the next couple of days.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Out of memory exception
Reply #4 - Mar 27th, 2013 at 3:34pm
Print Post  
On the PM page you can find updated version that catches these exceptions for nodes too. We can't see any adverse effect from catching and ignoring them, the borders still seem to be drawn correctly and there isn't any obvious memory usage spike. Our theory is that GDI+ native code returns some status code that's not interpreted correctly by the .NET wrapper class, and the wrapper unnecessarily throws a CLR out-of-mem exception for that code.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
jf2020
Junior Member
**
Offline


I love FlowChart!

Posts: 63
Joined: Feb 23rd, 2006
Re: Out of memory exception
Reply #5 - Apr 5th, 2013 at 7:14am
Print Post  
Good morning,

I have many trouble upgrading to V6.0.2 on our production version. For instance Pen for ShapeNode is now null by default . I tried to create a Theme but Pen is still null. Would it be possible to send me the code change you did to fix this exception so taht I can include it in my 5.8 version. I'm already using a custome compiled version of FlowChart, so adding this is the easiest path for me now.

JF
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Out of memory exception
Reply #6 - Apr 5th, 2013 at 7:38am
Print Post  
You can find updated .cs files on the PM page. Search for this line to find the relevant changes:

if (options.CatchGdiPlusExceptions)

Regarding moving to the new styling system, you can find some information here (check the Beware of Null ... part):
http://www.mindfusion.eu/onlinehelp/flowchartnet/index.htm?Changes_in_Control_s_...

So if you have code like this:
node.Pen.Color = Color.Black;
node.Pen.Width = 3;

you can replace it with
node.Pen = new Pen(Color.Black, 3);

or create node.Style and set Stroke and StrokeThickness in the Style.

When custom drawing, do not use Pen, Brush and Font directly, but EffectivePen, EffectiveBrush and EffectiveFont to get values resolved first from local properties if set, then styles and finally themes.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint