Metapyziks's picture

SDL_GL_GetCurrentContext not found at window initialization

I've been using OpenTK for a few years now without issue, but since updating to use the nuget version a few weeks ago I haven't been able to run any new projects using any recent builds of OpenTK.

Each time I get an EntryPointNotFoundException at Sdl2GraphicsContext.cs line 317, "Unable to find an entry point named 'SDL_GL_GetCurrentContext' in DLL 'SDL2.dll'". I get this with the last few nuget builds (all the ones from this year I think, I'll have to verify this), the pre-built download from this site, and building manually from opentk/opentk.git (Debug and Release). However, the examples all seem to work in both the pre-built download and a manual build.

Some other info that may be useful:
OS: Windows 8.1 (64 bit)
GPU: AMD Radeon HD 7850
.NET: 4.5

Here's a minimal snippet that produces the error for me:

using OpenTK;
 
namespace OpenTKTest
{
    class Program : GameWindow
    {
        static void Main(string[] args)
        {
            using (var app = new Program()) {
                app.Run();
            }
        }
    }
}

Literally if I just create a new project, add OpenTK as a reference, and add this code, I get the error.

I've heard of one other person that has a similar issue (or at least an issue that meant they couldn't use the latest versions of OpenTK), but apart from that I can't find anything else online about this. I can't think of anything else I installed / updated that could have caused this outside of updating OpenTK, and yet this obviously isn't a widespread issue.


Comments

Comment viewing options

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

Can you please post the debug output from a debug build of the library?

It appears that OpenTK is using the SDL2 backend. It may be that there is a stray/old SDL2.dll in your dll search path that is somehow missing this method.

You can force OpenTK to use the native win32 backend instead:

using OpenTK;
 
namespace OpenTKTest
{
    class Program : GameWindow
    {
        static void Main(string[] args)
        {
            var options = new ToolkitOptions
            {
                 Backend = PlatformBackend.PreferNative
            };
 
            using(Toolkit.Init(options))
            using (var app = new Program()) {
                app.Run();
            }
        }
    }
}

Alternatively, if you wish to use the SDL2 backend you can copy SDL2.dll from opentk/Dependencies to your output directory.

Metapyziks's picture

I hadn't realised that it wasn't always using SDL2, but forcing it to use the native backend has fixed the issue. I'll see if I can find the offending SDL2.dll that was causing the issue too.

Here's the debug log anyway:

GraphicsMode.Default = Index: , Color: 32 (8888), Depth: 16, Stencil: 0, Samples: 0, Accum: 0 (0000), Buffers: 2, Stereo: False
SDL2 is supported
Detected configuration: Windows / .Net
[SDL2] InputDriver failed to init Joystick subsystem. Error: CoInitialize() DirectX error -2147417850
[SDL2] InputDriver failed to init GameController subsystem. Error: CoInitialize() DirectX error -2147417850
Creating GraphicsContext.
GraphicsMode: Index: , Color: 24 (8880), Depth: 32, Stencil: 0, Samples: 0, Accum: 0 (0000), Buffers: 2, Stereo: False
IWindowInfo: OpenTK.Platform.SDL2.Sdl2WindowInfo
GraphicsContextFlags: Default
Requested version: 1.0
System.EntryPointNotFoundException: Unable to find an entry point named 'SDL_GL_GetCurrentContext' in DLL 'SDL2.dll'.

Thank you for spotting the problem, and also for providing such a fantastic library!

the Fiddler's picture

Unless you have a specific requirement, I'd recommend using the native backend. It's faster and better tested than the SDL2 backend, at least on Windows and Mac OS X.

It may be that some application has installed a beta version of SDL2.dll into C:/Windows/System32 or somewhere else in your path. I'll add a version check to ensure we ignore versions prior to 2.0.0.

the Fiddler's picture

A workaround to this issue was added in https://github.com/opentk/opentk/pull/126

You should now be able to use OpenTK without forcing the native backend.

Metapyziks's picture

That's great, thank you.

Incidentally I did find the SDL2.dll, it was in the binary directory of the game Garry's Mod, which I must have included in $PATH$ at some point.