tbarela's picture

GraphicsContext.CreateDummyContext() throws NullReferenceException.

Hi all,

I'm on winxp, and using the most recent nightly build of OpenTK( v1.1.0.0, 2011-11-11).

I'm trying to use Tao.Glfw & glfw 2.6 to handle my display/input needs. I do the normal initialization stuff with glfw, and then call CreateDummyContext(), which throws a NullReferenceException.

if(Glfw.glfwInit() != 1)
	throw new Exception("glfwInit() failed.");
if(Glfw.glfwOpenWindow(1024,768,8,8,8,8,16,8,Glfw.GLFW_WINDOW) != 1)
	throw new Exception("glfwOpenWindow() failed.");
dummyContext = GraphicsContext.CreateDummyContext();//<---boom!

I've read these similar posts like http://www.opentk.com/node/2713 and http://www.opentk.com/node/1877 . Is this functionality broken, or am I missing something here? If it is broken, will it be fixed anytime soon?

Thanks ahead of time.


Comment viewing options

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

I have met with the same issue.
It is a bug of CreateDummyContext().

I'm using the opentk-2011-11-11.zip, on Windows 7.

I found the solution of this issue.
Some changes are needed in the OpenTK source code.

In "Platform\Dummy\DummyGLContext.cs", replace the constructor
public DummyGLContext(ContextHandle handle)
with this

public DummyGLContext(ContextHandle handle)
    Handle = handle;
private static bool PlatformApiLoaded = false;
private delegate IntPtr GetProcAddress( string functionName );
private static GetProcAddress getProcAdressFunc = null;
private static void InitializeOpentkForDummyContextCreation()
    if( PlatformApiLoaded ) { return; }
    if( Configuration.RunningOnWindows )
        getProcAdressFunc = Platform.Windows.Wgl.GetProcAddres;
        PlatformApiLoaded = true;
    //else if( other platform ){ ... }

and, replace this function
public override IntPtr GetAddress( string function )
with this code

public override IntPtr GetAddress( string function )
    return getProcAdressFunc( function );

And when you creating dummy context, call these code to initialize OpenTK.

IntPtr hRC;// handle of the external rendering context
GraphicsContext dummyContext = GraphicsContext.CreateDummyContext( new ContextHandle( hRC ) );
// Don't use CreateDummyContext() overload.
OpenTK.Platform.IWindowInfo windowInfo = OpenTK.Platform.Utilities.CreateDummyWindowInfo();
dummyContext.MakeCurrent( windowInfo );
// now you can call the OpenTK functions.