CreateDummyContext throws an exception in 1.1 if there is no OpenTK context before #52

Closed
Baljak opened this Issue Jan 23, 2014 · 3 comments

Comments

Projects
None yet
2 participants
@Baljak

Baljak commented Jan 23, 2014

In 1.0, I used the method CreateDummyContext to share an external OpenGL context with OpenTK ones before any OpenTK context was created.

Now it does not work anymore, the method throws this exception:

A problem occurred: System.PlatformNotSupportedException: Operation is not supported on this platform.
at OpenTK.Platform.Utilities.CreateGetAddress()
at OpenTK.Graphics.GraphicsContext.CreateDummyContext(ContextHandle handle)

If an OpenTK context is created before the call to CreateDummyContext, everything works fine.

@ghost ghost assigned thefiddler Jan 23, 2014

@thefiddler

This comment has been minimized.

Show comment Hide comment
@thefiddler

thefiddler Jan 23, 2014

Contributor

This is a regression from 1.0, will investigate.

You can use one of the following GraphicsContext constructors as a workaround:

// If you are using an external library that implements
// its own context management (for example, SDL):
var external_context = new GraphicsContext(
    new ContextHandle( /* IntPtr handle of external context */ ),
    (name) => /* GetProcAddress(name) from external library */,
    () => /* GetCurrentContext() from external library */);

// If you wish to let OpenTK autodetect
// how to retrieve the context through
// WGL/GLX/AGL/CGL:
var external_context = new GraphicsContext(
    ContextHandle.Zero, // retrieve handle of current context
    null); // reserved

Barring the present bug, GraphicsContext.CreateDummyContext() is equivalent to the second method.

Note that the second method will only work on platforms with a native OpenTK backend. (Right now, this means desktop Windows, Linux/X11 and Mac OS X.) The first method will work everywhere.

Edit 1
See example code here: https://github.com/thefiddler/opentk-perftest/blob/master/test-sdl2-opentk-external/Program.cs#L34

Edit 2
Try calling Toolkit.Init() before using CreateDummyContext(). Does it work now?

Contributor

thefiddler commented Jan 23, 2014

This is a regression from 1.0, will investigate.

You can use one of the following GraphicsContext constructors as a workaround:

// If you are using an external library that implements
// its own context management (for example, SDL):
var external_context = new GraphicsContext(
    new ContextHandle( /* IntPtr handle of external context */ ),
    (name) => /* GetProcAddress(name) from external library */,
    () => /* GetCurrentContext() from external library */);

// If you wish to let OpenTK autodetect
// how to retrieve the context through
// WGL/GLX/AGL/CGL:
var external_context = new GraphicsContext(
    ContextHandle.Zero, // retrieve handle of current context
    null); // reserved

Barring the present bug, GraphicsContext.CreateDummyContext() is equivalent to the second method.

Note that the second method will only work on platforms with a native OpenTK backend. (Right now, this means desktop Windows, Linux/X11 and Mac OS X.) The first method will work everywhere.

Edit 1
See example code here: https://github.com/thefiddler/opentk-perftest/blob/master/test-sdl2-opentk-external/Program.cs#L34

Edit 2
Try calling Toolkit.Init() before using CreateDummyContext(). Does it work now?

@Baljak

This comment has been minimized.

Show comment Hide comment
@Baljak

Baljak Jan 23, 2014

It works with Toolkit.Init(), thanks!

Baljak commented Jan 23, 2014

It works with Toolkit.Init(), thanks!

@thefiddler thefiddler modified the milestones: 1.1.1, 1.1.0 Feb 17, 2014

@Mailaender Mailaender referenced this issue in OpenRA/OpenRA Mar 1, 2014

Closed

ported renderer to OpenTK #2408

thefiddler added a commit that referenced this issue Mar 13, 2014

@thefiddler

This comment has been minimized.

Show comment Hide comment
@thefiddler

thefiddler Mar 15, 2014

Contributor

This is now fixed.

Contributor

thefiddler commented Mar 15, 2014

This is now fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment