Crash with KryptonToolkit 4

Topics related to the Krypton Toolkit.

Moderators: Phil Wright, Chris Porter

Crash with KryptonToolkit 4

Postby aZoun » Mon Sep 28, 2009 10:34 pm

I get a ArgumentException exception in my program that uses KryptonToolkit 4 in some clients machines. I haven't found a way to reproduce the error.

This is the stack that I get:
Code: Select all
System.ArgumentException: Parameter is not valid.
at System.Drawing.Font.ToLogFont(Object logFont, Graphics graphics)
at System.Drawing.Font.ToLogFont(Object logFont)
at System.Drawing.Font.ToHfont()
at System.Windows.Forms.Control.FontHandleWrapper..ctor(Font font)
at System.Windows.Forms.Control.get_FontHandle()
at System.Windows.Forms.Control.get_FontHandle()
at System.Windows.Forms.Control.SetWindowFont()
at System.Windows.Forms.Control.OnHandleCreated(EventArgs e)
at System.Windows.Forms.ProgressBar.OnHandleCreated(EventArgs e)
at System.Windows.Forms.Control.WmCreate(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)

Is there any way to avoid this bug?
Thanks
aZoun
 
Posts: 18
Joined: Mon Sep 28, 2009 10:28 pm

Re: Crash with KryptonToolkit 4

Postby Phil Wright » Tue Sep 29, 2009 2:01 pm

Can you tell me the operatig system you are using? Are you running the application natively or running it via Citrix or Remote Desktop? Is this happening when you come back from a screensaver or from unlock?
Phil Wright
Site Admin
 
Posts: 2720
Joined: Thu Apr 13, 2006 2:55 pm
Location: Melbourne, Australia

Re: Crash with KryptonToolkit 4

Postby aZoun » Tue Sep 29, 2009 6:27 pm

Occurs for these versions of Windows

Microsoft Windows NT 6.0.6002 Service Pack 2
Microsoft Windows NT 6.1.7100.0
Microsoft Windows NT 6.1.7600.0
Microsoft Windows NT 5.1.2600 Service Pack 2
Microsoft Windows NT 5.1.2600 Service Pack 3

What I can't tell you is when occurs, I haven't that information
aZoun
 
Posts: 18
Joined: Mon Sep 28, 2009 10:28 pm

Re: Crash with KryptonToolkit 4

Postby Phil Wright » Tue Sep 29, 2009 6:37 pm

The error itself from the call stack is in the progress bar which is odd because there is no progress bar in the toolkit. Are you sure that Krypton is the cause of the issue?
Phil Wright
Site Admin
 
Posts: 2720
Joined: Thu Apr 13, 2006 2:55 pm
Location: Melbourne, Australia

Re: Crash with KryptonToolkit 4

Postby aZoun » Tue Sep 29, 2009 6:52 pm

I think it is related to Krypton and the fonts loaded by default on windows and buttons, apparently tries to draw the control with a font that is not well supported or installed.
aZoun
 
Posts: 18
Joined: Mon Sep 28, 2009 10:28 pm

Re: Crash with KryptonToolkit 4

Postby Phil Wright » Tue Sep 29, 2009 6:57 pm

At this point I have no idea how to fix it as I do not understand what is the cause of the issue. You need a small app that goes wrong in a reproducable way so that I can then investigate it on my machine or a virtual machine.
Phil Wright
Site Admin
 
Posts: 2720
Joined: Thu Apr 13, 2006 2:55 pm
Location: Melbourne, Australia

Re: Crash with KryptonToolkit 4

Postby aZoun » Wed Sep 30, 2009 2:31 am

Ok, I will try to get more information and I'll let you know.

Regards
aZoun
 
Posts: 18
Joined: Mon Sep 28, 2009 10:28 pm

Re: Crash with KryptonToolkit 4

Postby Chris Porter » Wed Sep 30, 2009 4:21 am

For what it is worth, I saw this error very rarely at the last company I worked for. It seemed to happen more often on a single person's computer but was completely random and we were never able to find the source or a repeatable path to test it further. I did seem to be somewhat tied to the KryptonComboBox but don't put too much trust in that relationship. To make things even more vague, we were running on 2.8.5. I had hoped that upgrading them to 3.5.2 would resolve the issue but it was happening so infrequently that the upgrade cost (work hours) wasn't justified.
Chris Porter
 
Posts: 714
Joined: Fri Oct 12, 2007 5:39 am
Location: Oklahoma City, OK, US

Re: Crash with KryptonToolkit 4

Postby aZoun » Wed Sep 30, 2009 8:33 am

I created a version of my program without ProgressBar and I still receive the same error
aZoun
 
Posts: 18
Joined: Mon Sep 28, 2009 10:28 pm

Re: Crash with KryptonToolkit 4

Postby Phil Wright » Wed Sep 30, 2009 10:31 am

To be honest I am not sure how to proceed with fixing the problem. As the call stack shows nothing with Krypton it is hard to know where to start investigating the problem. Any ideas?
Phil Wright
Site Admin
 
Posts: 2720
Joined: Thu Apr 13, 2006 2:55 pm
Location: Melbourne, Australia

Re: Crash with KryptonToolkit 4

Postby Chris Porter » Thu Oct 01, 2009 1:31 am

I opened up the System.Drawing assembly in reflector and looked around. The best I can tell, there is a call in the 2 parameter overloaded version of ToLogFont that calls an unsafe method and if the result of that call isn't 0, it raises an exception. I didn't determine which exception related to the one raised here because I ran out of time. It does look like its trying to access a font through a core library using a font handle and its not correctly recognized. I'm curious if this is a case of a bad font call that might exist on certain machines and isn't properly cleared when the app is built.

Thoughts?
Chris Porter
 
Posts: 714
Joined: Fri Oct 12, 2007 5:39 am
Location: Oklahoma City, OK, US

Re: Crash with KryptonToolkit 4

Postby aZoun » Fri Oct 02, 2009 7:54 am

I also checked the code with Reflector and I think it must be a bad font installed. It may be caused when trying to use the fonts Segoe or Calibri, many teams still are not installed or are other versions and Krypton may failure at making use of them.
aZoun
 
Posts: 18
Joined: Mon Sep 28, 2009 10:28 pm

Re: Crash with KryptonToolkit 4

Postby RobIII » Thu Dec 10, 2009 9:06 pm

Same problem here...

Code: Select all
Parameter is not valid
   at System.Drawing.Font.ToLogFont(Object logFont, Graphics graphics)
   at System.Drawing.Font.ToLogFont(Object logFont)
   at System.Drawing.Font.ToHfont()
   at System.Windows.Forms.Control.FontHandleWrapper..ctor(Font font)
   at System.Windows.Forms.Control.get_FontHandle()
   at System.Windows.Forms.Control.get_FontHandle()
   at System.Windows.Forms.Control.SetWindowFont()
   at System.Windows.Forms.Control.OnHandleCreated(EventArgs e)
   at System.Windows.Forms.ProgressBar.OnHandleCreated(EventArgs e)
   at System.Windows.Forms.Control.WmCreate(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)


Maybe useful information: I am using (inherited) KryptonForms.

Some more (seemingly related) stack traces:

Code: Select all
Error creating window handle
   at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
   at System.Windows.Forms.Control.CreateHandle()
   at System.Windows.Forms.ProgressBar.CreateHandle()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.ControlCollection.Add(Control value)
   at System.Windows.Forms.WindowsFormsUtils.ReadOnlyControlCollection.AddInternal(Control value)
   at System.Windows.Forms.ToolStripControlHost.SyncControlParent()
   at System.Windows.Forms.ToolStripControlHost.OnParentChanged(ToolStrip oldParent, ToolStrip newParent)
   at System.Windows.Forms.ToolStripItem.set_ParentInternal(ToolStrip value)
   at System.Windows.Forms.ToolStrip.SetDisplayedItems()
   at System.Windows.Forms.StatusStrip.SetDisplayedItems()
   at System.Windows.Forms.ToolStrip.OnLayout(LayoutEventArgs e)
   at System.Windows.Forms.StatusStrip.OnLayout(LayoutEventArgs levent)
   at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
   at System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(IArrangedElement affectedElement, String affectedProperty)
   at System.Windows.Forms.Layout.LayoutTransaction.DoLayout(IArrangedElement elementToLayout, IArrangedElement elementCausingLayout, String property)
   at System.Windows.Forms.ToolStrip.DoLayoutIfHandleCreated(ToolStripItemEventArgs e)
   at System.Windows.Forms.ToolStrip.OnItemVisibleChanged(ToolStripItemEventArgs e, Boolean performLayout)
   at System.Windows.Forms.ToolStripItem.OnVisibleChanged(EventArgs e)
   at System.Windows.Forms.ToolStripItem.SetVisibleCore(Boolean visible)
   at System.Windows.Forms.ToolStripControlHost.SetVisibleCore(Boolean visible)
   at System.Windows.Forms.ToolStripItem.set_Visible(Boolean value)
   at KeenSystems.SmartMan.Mainform.uc_UpdateStatusChanged(Object sender, UpdateStatusChangedArgs e)
   at KeenSystems.SmartMan.Mainform.<>c__DisplayClass25.<uc_UpdateStatusChanged>b__24()
   at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
   at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
   at System.Windows.Forms.Control.InvokeMarshaledCallbacks()


Code: Select all
ArgumentException
   at System.Drawing.Font.ToLogFont(Object logFont, Graphics graphics)
   at System.Drawing.Font.ToLogFont(Object logFont)
   at System.Drawing.Font.ToHfont()
   at System.Windows.Forms.Control.FontHandleWrapper..ctor(Font font)
   at System.Windows.Forms.Control.get_FontHandle()
   at System.Windows.Forms.Control.get_FontHandle()
   at System.Windows.Forms.Control.SetWindowFont()
   at System.Windows.Forms.Control.OnHandleCreated(EventArgs e)
   at System.Windows.Forms.ProgressBar.OnHandleCreated(EventArgs e)
   at System.Windows.Forms.Control.WmCreate(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)


Hmm; just thinking... the progressbar is in a statusstrip...
User avatar
RobIII
 
Posts: 6
Joined: Thu Dec 10, 2009 9:01 pm
Location: Netherlands

Re: Crash with KryptonToolkit 4

Postby Consulteware » Thu Dec 17, 2009 3:02 am

The problem it is on the MDI Form, just check this post on microsoft .Net Support aticle.

http://support.microsoft.com/kb/949458/en-gb

The MDI Form cannot have any hidden object, either from the programmer either from Krypton, that is the main problem.

I have exactly the same problem.

The steps that I make to make some avoiding that messages (But I cannot solve the problem).

On the Load event avoid to hide or show objects, try to avoid to work with hidden objects.
Stop working with maximizing or resizing the MDI windows.

This small solution has at least stopped to appear that message to my users in 70% but did not kill the problem, I do think that Krypton Form should have something too, but I cannot verify that too, but Phil Wright or Chris Porter can check that.

I hope this helps.

P.S.: I'm trying now one new solution for this, just give 1 or 2 weeks and then I will tell if something works, if I post another Reply it is good, if I do not, the problem it maintains.
Consulteware
 
Posts: 8
Joined: Tue Aug 18, 2009 6:02 am

Re: Crash with KryptonToolkit 4

Postby Dmitry » Thu Jan 07, 2010 4:19 am

Hi everybody, the problem is in User Objects, windows have a restriction in 10000 User Object per application (don't know about XP and others, but in Win 7 x64 this is so), looks a lot, but Krypton creates several UO for each control you place on the form. Even for the controls of the same type.
So if you have a complex UI, you find 10,000 UO restriction too tight.

Solution: destroy unused UI objects. Not simply hide, but Dispose, and recreate when needed.Or reuse the same controls if you have the same forms fro example. Yes I know, this will slow down everything. However I don't think that there is another solution.

PS: you can see number of used UO in Task Manager's Processes tab.
Dmitry
 
Posts: 8
Joined: Mon Aug 31, 2009 12:22 am

Re: Crash with KryptonToolkit 4

Postby Edgar Ferreira » Thu Jan 07, 2010 5:35 am

Hi!
I've experienced this issue a lot and seemed to occur randomly (but very often).

Conditions when exception ocurred:
1. I had a StatusStrip ProgressBar
2. I had a Thread (other then main) that hide/show the progress bar
3. I have some Windows Forms controls (TreeViews and stuff) and usually set their font equal to Krypton palette's fonts

Implemented solutions:
1. I removed the progress bar and replaced it for an animated GIF
2. Everywhere I use a Krypton palette font, I create a new font object: treeView.Font = new Font(KryptonFont, FontStyle.Regular)

Since the implementation of solution 1, I never faced this issue.
My guess is that the progress bar inside status strip retrieves this exception when the status strip is drawn with krypton style (don't know what the font has to do with the progress bar, maybe a Windows Forms bug).
You can also try to set the StatusStrip RenderMode=System.
Edgar Ferreira
 
Posts: 132
Joined: Thu Mar 26, 2009 8:59 pm
Location: Coimbra, Portugal

Re: Crash with KryptonToolkit 4

Postby Chris Porter » Sat Jan 09, 2010 4:59 am

Consulteware wrote:The problem it is on the MDI Form, just check this post on microsoft .Net Support aticle.


I've seen this error in a few different applications and none of them were MDI apps. Some instances of the error might be related to MDI issues but it isn't the source of all of the errors.

Dmitry wrote:Hi everybody, the problem is in User Objects, windows have a restriction in 10000 User Object per application (don't know about XP and others, but in Win 7 x64 this is so), looks a lot, but Krypton creates several UO for each control you place on the form.


I'm guessing you are talking about GDI Objects. Krypton does use GDI heavily but was not an issue when I received this error before. The only time my app has hit the 10k limit was when I had a dialog form that was heavy on controls (most of which were C1TrueDBGrids) and I wasn't manually disposing the form when I was done with it. FYI: If you do not intentionally call .Dispose() on a form that was shown using ShowDialog(), it will remain in memory and be a huge leak. Always ensure you get rid of the form when you are done.

Like with MDI, hitting the 10k limit of GDI Objects could definitely cause the above error (and a whole slew of other ones) but it is not the only cause of this issue.
Chris Porter
 
Posts: 714
Joined: Fri Oct 12, 2007 5:39 am
Location: Oklahoma City, OK, US

Re: Crash with KryptonToolkit 4

Postby Dmitry » Sat Jan 16, 2010 12:11 pm

Chris Porter wrote:I'm guessing you are talking about GDI Objects.


No. I'm talking about User Object.

Also Page Faults, why there are so many page faults? I have 8 Gb and half of it is free.

And yes, each Krypton form that is not disposed manually is a leak. :(
Attachments
screen2.png
screen2.png (18 KiB) Viewed 1108 times
Dmitry
 
Posts: 8
Joined: Mon Aug 31, 2009 12:22 am

Re: Crash with KryptonToolkit 4

Postby Tommy Carlier » Mon Jan 18, 2010 9:47 pm

We used to have such a problem with one of our older applications (not using Krypton, because it didn't exist back then). It was an MDI-application, and after gathering enough statistics, we found out that users were keeping 10-15 child windows open at the same time, and those windows contained a lot of controls. Our solution was to build a mechanism that would keep track of the resources (number of User-objects, GDI-objects, ...) and if some limit was reached, it would try to close some of the windows. It would close the windows that did not have changes to save and that were least recently displayed (we kept track of when windows received focus). It was kind of a Garbage Collector for open windows. After that, we didn't have the problem anymore.

P.S.: another tip to avoid leaking resources: always Dispose dialogs after closing them. Preferably use the using-statement, like this:
Code: Select all
using (MyForm form = new MyForm())
{
  if (form.ShowDialog(this) == DialogResult.OK)
  {
    ...
  }
}
Tommy Carlier
 
Posts: 102
Joined: Sat May 06, 2006 9:51 pm
Location: Belgium

Re: Crash with KryptonToolkit 4

Postby Chris Porter » Sat Jan 23, 2010 5:04 am

Dmitry wrote:No. I'm talking about User Object.
...
And yes, each Krypton form that is not disposed manually is a leak. :(

Sorry, you are correct, I've never looked at the user object count before. I'll keep an eye on that in future winform development projects. I can't tell you why you are seeing that many page faults but I also wouldn't trust numbers coming from a vhosted application as you never know what VS is doing in the background.

As for the memory leak, that issue I posted is not specific to Krypton, but happens in SWF as well. Windows forms that are opened as dialogs are not disposed of until you force the dispose or the garbage collector gets off its ass and decides to do some work. Tommy's suggestion is definitely a best practice to prevent this.

To get back to your original post, what are you doing to create so many user objects? How is your form setup? How many controls are you putting on it?
Chris Porter
 
Posts: 714
Joined: Fri Oct 12, 2007 5:39 am
Location: Oklahoma City, OK, US

Next

Return to Krypton Toolkit

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron