Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Reopening of bug 2506? GLControl inside a user control crashes during design time #49

epiuze opened this Issue · 8 comments

3 participants


I would like to fill a request to reopen bug 2506:

I've tried both compiling OpenTK 1.1-rc1 from sources and the current release (opentk-2014-01-15) to no avail.

My code compiles and runs fine, but visual studio 2012 crashes when I enter design mode for a form into which I put a custom user control that contains a docked GLControl.

Copied from link above, the workflow looks like this:

  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
@thefiddler thefiddler referenced this issue from a commit
@thefiddler thefiddler [GLControl] Use dummy context in design mode
Creating a GraphicsContext with null parameters is not a guarantee that
we will get a dummy context that does not call any OpenGL functions. We
need to explicitly define and construct a dummy context that is safe to
use inside the designer.

Affects issue #49

Thanks for the bug report. I wasn't able to reproduce the issue using these steps, but I have identified a possible regression caused by the external-context fixes in 1.1-beta4.

I have committed a potential fix in c2e3328, can you please try that and see if this resolves the issue?

You also need to make sure that you are not calling any OpenGL functions when running in design mode, as an OpenGL context will not generally be available inside the designer.


I tried the updated code without success. It seems that there is no way to properly detect whether we are in design mode or not. Try to attach the following paint callback to the glControl in the workflow stated above:

    private void glControl1_Paint(object sender, PaintEventArgs e)
        if (LicenseManager.UsageMode == LicenseUsageMode.Designtime) return;

        GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

This should make it crash.


Just to add a bit more to that, I've also tried to test whether both the UserControl1's and the glControl's Load(object sender, EventArgs e) had been called by setting a boolean, something like:

        if (LicenseManager.UsageMode == LicenseUsageMode.Designtime || !formLoaded || !glLoaded) return;

but the designer (and VS2012) still crashes when given focus.


IIRC, LicenseManager.UsageMode is only valid inside the constructor of a Control. You can call it from the constructor and store the value to a readonly field. See also:


Thanks, that seems to be working. Is there another/better way to handle this issue though? It feels a bit more like a hack than a fix. Is there any mention of this in the OpenTK wiki or documentation?


A quick check shows that it is not documented outside of bug reports / forum posts. We should update the documentation for the 1.1 release.

Design-time instability is a very common issue with custom controls, most WinForms developers will come across this at one point or another. In my experience, the check-for-design-mode-and-bail-out hack is the accepted solution.

That said, I'm open to suggestions for a less hacky approach.

Very old versions of OpenTK 0.3.x would create a real OpenGL context in design mode, which came a whole different set of issues (instability, memory exhaustion, outright IDE crashes.) Any OpenGL error during development could potentially bring down the whole IDE, making debugging a total nightmare.

Loading the OpenGL entry points with something harmless (a nop function) is theoretically possible, but extremely challenging to implement - and would still fail with functions returning data (e.g. GL.ReadPixels). It would be an interesting technical exercise in calling conventions and managed-unmanaged thunks, but little more than that.

Ideas welcome.


Thanks for the input - I can appreciate the difficulty in fixing this issue in a more formal way. I'm fairly novice with VS C# and I still have a lot to learn. Thanks again!

@epiuze epiuze closed this
@epiuze epiuze reopened this

Also, the Component.DesignMode (Control inherits from Component) property can be used to check the prescence of design mode. Interestingly, this property is not yet set in the constructor (will probably need to use LicenseManager.UsageMode in constructor if needed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.