Anonymous's picture

NullReferenceException when repeatedly creating and destroying forms containing GLControl instances

Project:The Open Toolkit library
Category:bug report

I have an application which is creating and disposing several windows, each with a single GLControl instance as a unit test.

Sometimes the following exception is thrown. The problem is intermittent, running the same unit tests does not always generate the exception.

System.NullReferenceException: Object reference not set to an instance of an object.
at OpenTK.Platform.Windows.Wgl.Arb.SupportsExtension(WinGLContext context, String ext)
at OpenTK.Platform.Windows.WinGLContext.OpenTK.Graphics.IGraphicsContextInternal.LoadAll()
at OpenTK.Graphics.GraphicsContext.OpenTK.Graphics.IGraphicsContextInternal.LoadAll()
at OpenTK.GLControl.OnHandleCreated(EventArgs e)
at System.Windows.Forms.Control.WmCreate(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.UserControl.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)


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
gareththegeek's picture


Email me if you cannot recreate this problem or need further info, I have a unit test in NUnit which is recreating the problem every third or fourth go round.

objarni's picture


What are the exact steps of the unit test? Can you show some (pseudo) code?

the Fiddler's picture


I haven't been able to reproduce this exception, but GLControl.MakeCurrent() fails every 3rd or 4th time for some reason (you can reproduce that by running a WinForms example repeatedly).

These problems may be linked, investigating.

Edit: a full stacktrace would certainly help. Try running the test with debug version of OpenTK.dll and OpenTK.pdb (you can simply copy them over the existing dlls). The NRE should now contain line numbers that will point to the exact location of the error inside OpenTK.

the Fiddler's picture


Status:open» in progress (review)

Ok, I have committed several changes to improve stability and plug resource leaks related to the GLControl. I have tested up to 500 GLControls and everything seems stable now.

Can you please update to SVN head (rev. 1752+) and check if the problem persists? If it does, I am going to need the exact line number of the error (the post above describes how to obtain that).

gareththegeek's picture


Thanks for the prompt reply.

I have downloaded svn head revision (1754) and the problem seems to be resolved!

BTW what has happened to the glFog commands? Since rebuilding the head revision they are no longer defined?

the Fiddler's picture


Version:0.9.7» 0.9.x-dev
Status:in progress (review)» fixed

Thanks for testing, marking this as fixed.

Fogv functions have been renamed to Fog (likewise for Materialv, Uniform1v, etc). This was intentional: all related functions are now overloads of each other.

the Fiddler's picture


The issues related to Fog functions should be resolved now.

the Fiddler's picture


Status:fixed» closed

Closing issues fixed in 0.9.8.