
GLControl inside a user control crashes during design time
Posted Wednesday, 25 May, 2011 - 04:19 by terryhau| Project: | The Open Toolkit library |
| Version: | 1.0-2010-10-06 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | the Fiddler. |
| Status: | in progress (review) |
Jump to:
When you place a GLControl directly on to a form, it works fine.
However if you put a GLControl on to a user control and put that user control on to the form,
the GLControl creates a rendering context during design time and often it fails, causing crashes or errors.
It appears to be a problem or "feature" of the WinForms designer. Nested controls are alive during design time.
If you have code that draws to the GLControl, you will see it being drawn during design time.
http://support.microsoft.com/kb/839202
From what I've read, the way around it is to use if(LicenseManager.UsageMode == LicenseUsageMode.Designtime) instead of if(DesignMode)
but this test only works in the control's constructor. However it can be evaluated in the constructor and stored for later use.
I think if all the if(DesignMode) checks in GLControl.cs are changed to use a more reliable check, it should fix the problem.
http://dotnetfacts.blogspot.com/2009/01/identifying-run-time-and-design-...
http://stackoverflow.com/questions/34664/designmode-with-controls
It's easy to reproduce but I will upload a sample project if I can figure out how.
1. Create new WinForms project
2. Add new user control called UserControl1
3. Drop a GLControl on to the user control
4. Rebuild project
5. Drop UserControl1 on to main form
6. GLControl should crash


Comments
#1
#2
You can avoid this problem by using
if (!DesignMode)in your controlls Load and Paint function.See example.
#3
SVN trunk r3068 now contains a potential fix for this issue. Can you please check that it no longer occurs?
#4
For me only
System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv"worked.In trunk revision 3069 not fixed!
#6
Do not rely on the DesignMode property - it will return false when your usercontrol is placed into a Form. The correct way to check for design-time is to use the static LicenseManager.UsageMode property:
Checking process name probably isn't a good idea either, since another IDE (such as SharpDevelop) will have a different process name.