
GetCurrentContext null
Posted Monday, 3 May, 2010 - 04:48 by Veiva| Project: | The Open Toolkit library |
| Version: | 1.0-2010-10-06 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
(Sorry if this is fixed in SVN; haven't had time to test it)
Steps to reproduce:
- Create an external OpenGL display context (I used a wrapper I wrote over the Allegro game programming library to do this)
- Get a handle to the context and the window and create the corresponding ContextHandle and IWindowInfo
- 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
#1
This has been fixed in SVN. Checkout instructions: http://www.opentk.com/project/svn
#2
Closing issues fixed in opentk-1.0-2010-10-06 release.