its's picture

Dummy context creation fails on Windows

Project:The Open Toolkit library
Version:1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:open
Description
static GraphicsContext OpenTK.Graphics.GraphicsContext.CreateDummyContext( ContextHandle handle )
 
static GraphicsContext OpenTK.Graphics.GraphicsContext.CreateDummyContext()
 
OpenTK.Graphics.GraphicsContext.GraphicsContext( ContextHandle handle, IWindowInfo window )
 
OpenTK.Graphics.GraphicsContext.GraphicsContext( 
	ContextHandle handle,
	IWindowInfo  window, 
	IGraphicsContext shareContext,
	int  major,
	int  minor, 
	GraphicsContextFlags flags )

These functon and constructors always fail with NullReferenceException at OpenTK.Platform.Windows.Wgl.GetCurrentContext().
(Delegates in the internal Wgl class are not initialized.)
Because of this issue, OpenTK cannot be used with 'external' OpenGL rendering context (i.e., created by calling wglCreateContext at outside of OpenTK).

Plrease add the below codes to fix this issue.
This changes will fix CreateDummyContext() and CreateDummyContext( ContextHandle handle ) on Windows.

// In "DummyGLContext.cs",
// change the constructor "DummyGLContext.DummyGLContext(ContextHandle handle)"
// and function "IntPtr GetAddress( string function )".
 
        public DummyGLContext(ContextHandle handle)
        {
            Handle = handle;
            InitializeOpentkForDummyContextCreation();
        }
 
        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 )
            {
                System.Diagnostics.Debug.WriteLine( "Wgl.LoadAll()" );
                Platform.Windows.Wgl.LoadAll();
                getProcAdressFunc = Platform.Windows.Wgl.GetProcAddres;
 
                PlatformApiLoaded = true;
            }
        }
 
 
        // ...
 
 
        public override IntPtr GetAddress( string function )
        {
            return getProcAdressFunc( function );
        }

Comments

Comment viewing options

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

#1

Assigned to:its» Anonymous
the Fiddler's picture

#2

Thanks for the bug report. I am trying to determine whether this approach will work on all platforms (on first glance, this may not work on Linux).

If this is indeed non-portable, then it might be necessary to change the API slightly to accept an external GetAddress implementation (most OpenGL libraries offer this, e.g. SDL_GetProcAddress for SDL and glfwGetProcAddress for GLFW).