Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Overview window having problems drawing text (Read 2883 times)
David Long
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 125
Location: England
Joined: Oct 23rd, 2006
Overview window having problems drawing text
Dec 11th, 2020 at 11:52am
Print Post  
Is there any reason why the overview window would have problems drawing text.  This is the call stack...

Message               : Parameter is not valid.
Source                : System.Drawing
Stack Trace           :
   at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
   at System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
   at MindFusion.Drawing.GdiGraphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
   at MindFusion.Diagramming.ShapeNode.c2fa8ddcea66de378dd2b3effa46b7080(c48b3fdd1c915
6f9901cdeee6911ffe6e c709ceac15c918fc392a6d51df8089edc)
   at MindFusion.Diagramming.ShapeNode.caf4474dadf19b15a82502e8142e562c6(IGraphics c6c92d7b0a001e45905428290158c2b17, RectangleF ce628c69113f2f8808f36872bc2738966, Boolean c9ad6e71c98bc3301de210ef60cbebaf6, Brush cfe6c9db5410bcfcba1e5ef84f3723807, Pen c70516b352fa4534e29f3eea90837a640, RenderOptions ccf51cc94bd4a2fb3622e3aa9f3d15511)
   at MindFusion.Diagramming.ShapeNode.DrawLocal(IGraphics graphics, RenderOptions options)
   at MindFusion.Diagramming.DiagramNode.Draw(IGraphics graphics, RenderOptions options)
   at MindFusion.Diagramming.Diagram.c36c1fca3b267b5451f759c0295c2805a(IGraphics c6c92d7b0a001e45905428290158c2b17, DiagramItem ca6e827fc07fcc9e1bcb0b1fce21834e2, Boolean c1e4be7b4a08ee92d4d8160fe7cdf183b, Nullable`1 cba5fe945e4bbdbc1273efda679d7f4fe)
   at MindFusion.Diagramming.Diagram.c85c9fb5f1477600f0b8e47a76b97a8a7(IGraphics c6c92d7b0a001e45905428290158c2b17, RectangleF cba5fe945e4bbdbc1273efda679d7f4fe, Boolean c4f62962e65ed617349113106456b7633)
   at MindFusion.Diagramming.Diagram.Draw(IGraphics graphics, RenderOptions options, RectangleF clipRect, Boolean noModifiedItems)
   at MindFusion.Diagramming.WinForms.Overview.c59dd069dc76431cfd80a56e288fb26d2(IGrap
hics c9a63e72f7d84bca7bcd11ec599cbc5ca, Rectangle c7eceaf45c8866e0268124a61e0f393e6)
   at MindFusion.Diagramming.WinForms.Overview.OnPaint(PaintEventArgs e)
   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.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

DavidL
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Overview window having problems drawing text
Reply #1 - Dec 11th, 2020 at 1:17pm
Print Post  
If none of the brush, font and string arguments are null when debugger stops on that exception, then it could be some problem in GDI+ drawing strings at very small scales. Our developer will do some tests with that.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
David Long
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 125
Location: England
Joined: Oct 23rd, 2006
Re: Overview window having problems drawing text
Reply #2 - Jan 26th, 2023 at 2:09pm
Print Post  
This exception has popped up again. Interestingly on the same laptop. Is there anymore help or information available?

DavidL
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Overview window having problems drawing text
Reply #3 - Jan 26th, 2023 at 2:46pm
Print Post  
This crashes for us when you halve the scale about 50 times, maybe that specific machine's video driver reaches the limit at larger scales -

Code
Select All
public Form1()
{
	InitializeComponent();
}

protected override void OnPaint(PaintEventArgs e)
{
	base.OnPaint(e);
	var state = e.Graphics.Save();
	e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
	e.Graphics.ScaleTransform(scale, scale);
	e.Graphics.DrawString(
		"scale: " + scale.ToString(),
		new Font("Arial", 20), Brushes.Black, 10, 10);
	e.Graphics.Restore(state);
}
private void button1_Click(object sender, EventArgs e)
{
	scale /= 2;
	Debug.WriteLine(scale);
	Invalidate();
}

float scale = 1; 



You could disable overview's DisplayText property when its ScaleFactor gets too small, or override Overview.OnPaint to catch and ignore the exception.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
David Long
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 125
Location: England
Joined: Oct 23rd, 2006
Re: Overview window having problems drawing text
Reply #4 - Jan 26th, 2023 at 3:30pm
Print Post  
Thanks for your prompt response Smiley

The override of OnPaint is only called when the form containing the Overview control is resized and not when the Overview control changes its contents. Is that OK or is something more needed?

DavidL
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Overview window having problems drawing text
Reply #5 - Jan 27th, 2023 at 9:54am
Print Post  
You are overriding overview's method, right? OnPaint is the only place it draws anything and is called as expected in our test -

Code
Select All
class OverviewEx : Overview
{
	protected override void OnPaint(PaintEventArgs e)
	{
		try
		{
			Debug.WriteLine("OnPaint");
			base.OnPaint(e);
		}
		catch
		{
			//DisplayText = false;
			//Invalidate();
		}
	}
} 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
David Long
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 125
Location: England
Joined: Oct 23rd, 2006
Re: Overview window having problems drawing text
Reply #6 - Jan 28th, 2023 at 9:28pm
Print Post  
Yes, that looks better. I was overriding the OnPaint in the dialog that contains the Overview control which is not the right thing to do!

How not to do it...

public partial class OverviewDialog : Form
    {
        public OverviewDialog()
        {
            InitializeComponent();
            
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            try
            {
                base.OnPaint(e);
            }

            catch
            {
                // Exception in base.OnPaint, ignore
            }
        }
    }
  
Back to top
 
IP Logged
 
David Long
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 125
Location: England
Joined: Oct 23rd, 2006
Re: Overview window having problems drawing text
Reply #7 - Nov 30th, 2023 at 6:35pm
Print Post  
We have had the same or similar problem reported with the DiagramView...

Message                 : Parameter is not valid.
Source                  : System.Drawing
Stack Trace             :
   at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
   at System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
   at MindFusion.Drawing.GdiGraphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
   at MindFusion.Diagramming.ShapeNode.c2fa8ddcea66de378dd2b3effa46b7080(c48b3fdd1c915
6f9901cdeee6911ffe6e c709ceac15c918fc392a6d51df8089edc)
   at MindFusion.Diagramming.ShapeNode.caf4474dadf19b15a82502e8142e562c6(IGraphics c6c92d7b0a001e45905428290158c2b17, RectangleF ce628c69113f2f8808f36872bc2738966, Boolean c9ad6e71c98bc3301de210ef60cbebaf6, Brush cfe6c9db5410bcfcba1e5ef84f3723807, Pen c70516b352fa4534e29f3eea90837a640, RenderOptions ccf51cc94bd4a2fb3622e3aa9f3d15511)
   at MindFusion.Diagramming.ShapeNode.DrawLocal(IGraphics graphics, RenderOptions options)
   at MindFusion.Diagramming.DiagramNode.Draw(IGraphics graphics, RenderOptions options)
   at MindFusion.Diagramming.Diagram.c36c1fca3b267b5451f759c0295c2805a(IGraphics c6c92d7b0a001e45905428290158c2b17, DiagramItem ca6e827fc07fcc9e1bcb0b1fce21834e2, Boolean c1e4be7b4a08ee92d4d8160fe7cdf183b, Nullable`1 cba5fe945e4bbdbc1273efda679d7f4fe)
   at MindFusion.Diagramming.Diagram.c85c9fb5f1477600f0b8e47a76b97a8a7(IGraphics c6c92d7b0a001e45905428290158c2b17, RectangleF cba5fe945e4bbdbc1273efda679d7f4fe, Boolean c4f62962e65ed617349113106456b7633)
   at MindFusion.Diagramming.Diagram.Draw(IGraphics graphics, RenderOptions options, RectangleF clipRect, Boolean noModifiedItems)
   at MindFusion.Diagramming.WinForms.DiagramView.cbdcbabce8bb735d287c1c0e3584d6497(IG
raphics c6c92d7b0a001e45905428290158c2b17, RectangleF c9261db5050cfcb2acba21bce194905d7, Boolean cdca9e96975ed25325aeab09ccb659e27)
   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 MindFusion.Diagramming.WinForms.DiagramView.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Is there anything we can do about this?
DavidL
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Overview window having problems drawing text
Reply #8 - Dec 4th, 2023 at 6:53am
Print Post  
This build calls each DrawString from within try / catch:
https://mindfusion.eu/_temp/diagwinforms_drawstring.zip

DiagramView now has same DisplayText property as Overview, so you could disable that at small zoom level to avoid the exception stack unwindings.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
David Long
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 125
Location: England
Joined: Oct 23rd, 2006
Re: Overview window having problems drawing text
Reply #9 - Dec 5th, 2023 at 3:35pm
Print Post  
I restrict the diagram's zoom level to 50% to 200%, so I don't think that it's a zoom-level problem.

DavidL
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Overview window having problems drawing text
Reply #10 - Dec 5th, 2023 at 4:03pm
Print Post  
Can you see in debugger what's the exact status value passed to CheckErrorStatus method?
https://learn.microsoft.com/en-us/windows/win32/api/gdiplustypes/ne-gdiplustypes...

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
David Long
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 125
Location: England
Joined: Oct 23rd, 2006
Re: Overview window having problems drawing text
Reply #11 - Dec 5th, 2023 at 4:12pm
Print Post  
This was a one-off report from a customer. I can't reproduce it, so let's leave it for now. Thanks for your help.
DavidL
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Overview window having problems drawing text
Reply #12 - Dec 5th, 2023 at 4:48pm
Print Post  
If your application collects error reports, try also logging exact string, font and layoutRectangle.

I've played with 20000 ShapeNodes with random texts and font sizes in StressTest example, but could not reproduce problems scrolling them around for a few minutes -

Code
Select All
for (int i = 0; i < nodes; ++i)
{
  ...
  n.Text = RandomString(15);
  n.Font = new Font("Segoe UI", 5f + 15f * (float)random.NextDouble());
}

static Random random = new Random();

static string RandomString(int length)
{
	const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	return new string(Enumerable.Repeat(chars, length)
		.Select(s => s[random.Next(s.Length)]).ToArray());
} 



Potentially there could be code leaking GDI+ objects in the app (say not disposing brushes or fonts), e.g. third party system.drawing based controls, or other types of diagram nodes, or any custom-draw event handlers. If that's happening, at some point GDI+ might be getting low on resources and DrawString failing because of that. If your application handles custom-draw events, maybe review them for disposing brushes, pens and fonts.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
David Long
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 125
Location: England
Joined: Oct 23rd, 2006
Re: Overview window having problems drawing text
Reply #13 - Dec 14th, 2023 at 5:06pm
Print Post  
I will have a look at the code and report what I find.
Thanks for you help.
DavidL
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint