Veiva's picture

GetCurrentContext null

Project:The Open Toolkit library
Version:1.0-2010-10-06
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

(Sorry if this is fixed in SVN; haven't had time to test it)

Steps to reproduce:

  1. Create an external OpenGL display context (I used a wrapper I wrote over the Allegro game programming library to do this)
  2. Get a handle to the context and the window and create the corresponding ContextHandle and IWindowInfo
  3. Create a new GraphicsContext with the ContextHandle and IWindowInfo

Code is as follows:

IntPtr hrc = wglGetCurrentContext(), hwnd = AllegroDisplayContext.GetHandle(Context.GetContext<AllegroDisplayContext>());
ContextHandle contextHandle = new ContextHandle(hrc);
IWindowInfo window = Utilities.CreateWindowsWindowInfo(hwnd);
graphicsContext = new GraphicsContext(contextHandle, window); // <- Exception

I think I found a fix as of the 1.0.0-rc1 code (at least it's working for me now):

public GraphicsContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, int major, int minor, GraphicsContextFlags flags)
        {
            lock (SyncRoot)
            {
                IsExternal = true;
 
                if (handle == ContextHandle.Zero)
                {
                    implementation = new OpenTK.Platform.Dummy.DummyGLContext(handle);
                }
                else if (available_contexts.ContainsKey(handle))
                {
                    throw new GraphicsContextException("Context already exists.");
                }
                else
                {
					IPlatformFactory factory = null; // Starting here
                    switch ((flags & GraphicsContextFlags.Embedded) == GraphicsContextFlags.Embedded)
                    {
						case false: implementation = Factory.Default.CreateGLContext(handle, window, shareContext, direct_rendering, major, minor, flags); factory = Factory.Default; break;
                        case true: implementation = Factory.Embedded.CreateGLContext(handle, window, shareContext, direct_rendering, major, minor, flags); factory = Factory.Embedded; break;
                    }
 
					if (GetCurrentContext == null)
						GetCurrentContext = factory.CreateGetCurrentGraphicsContext(); //Ending here
                }
 
                available_contexts.Add((implementation as IGraphicsContextInternal).Context, new WeakReference(this));
 
                (this as IGraphicsContextInternal).LoadAll();
            }
        }

Basically, the GetCurrentContext delegate is not assigned to when one creates a context as previously detailed. I believe, as far as I tried, CreateDummyContext also results in a crash.

I searched the issue list and didn't see this issue pop up recently...sorry in advance if it has (or has been fixed in SVN)!


Comments

Comment viewing options

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

#1

Status:open» fixed

This has been fixed in SVN. Checkout instructions: http://www.opentk.com/project/svn

the Fiddler's picture

#2

Version:1.0.0-rc1» 1.0-2010-10-06
Status:fixed» closed

Closing issues fixed in opentk-1.0-2010-10-06 release.