Rhedox's picture

X Error BadMatch in GameWindow Constructor when Major Version >= 3

Hello guys,
I recently started testing out OpenTK on Linux after some time on Windows but I can't get it to run. (Just for the record: I started a new project in MonoDevelopment. So there isn't any Windows stuff in there causing issues)
It already fails inside the constructor of the GameWindow Class:
Game game = new Game(1280, 720, OpenTK.Graphics.GraphicsMode.Default, "INSERT_GAME_NAME", OpenTK.GameWindowFlags.Default, DisplayDevice.Default, 3,3, OpenTK.Graphics.GraphicsContextFlags.ForwardCompatible);

Giving me the following error:
X Error of failed request: BadMatch (invalid parameter attributes)
Major opcode of failed request: 155 (GLX)
Minor opcode of failed request: 5 (X_GLXMakeCurrent)
Serial number of failed request: 66
Current serial number in output stream: 66

(Has to be something XServer and OpenGL context creation related.) I installed the latest Nvidia drivers and checked whether direct rendering is enabled.

If I change the major version to anything lower than 3 it suddenly works.
I didn't find an answer after searching for about an hour and I'm kinda desperate now.



Comment viewing options

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

It is possible that the Linux query for OpenGL version is returning a lower number than 3.3, or the driver/gpu configuration you have does not support it altogether.

Do know however that you can still use 3.3 even without specifying it as a minimum version like you are doing in the Game constructor.

Rhedox's picture

First I tried running the game with major version 2 and execute this:

Console.WriteLine("[Hardware] Detected GPU: " + GL.GetString(StringName.Vendor) + " " + GL.GetString(StringName.Renderer));
Console.WriteLine("[Hardware] Detected OpenGL Version: " + GL.GetString(StringName.Version));

The result was the expected OpenGL 4.4.

Second I tried glxinfo | more.

server glx vendor string: NVIDIA Corporation
server glx version string: 1.4
client glx vendor string: NVIDIA Corporation
client glx version string: 1.4
OpenGL version string: 4.4.0 NVIDIA 331.38
OpenGL shading language version string: 4.40 NVIDIA via Cg compiler
OpenGL context flags: (none)
OpenGL profile mask: (none)
OpenGL version string: 4.4.0 NVIDIA 331.38
OpenGL shading language version string: 4.40 NVIDIA via Cg compiler
OpenGL context flags: (none)
OpenGL profile mask: (none)

(My GPU is an GTX 680)

winterhell wrote:

Do know however that you can still use 3.3 even without specifying it as a minimum version like you are doing in the Game constructor.

How do I do this? I want 3.3 Features.

the Fiddler's picture

If you request OpenGL version >= 3.0, then OpenTK uses GLX_ARB_create_context to create the context. For versions below 3.0, OpenTK uses the older glXCreateContext instead. In your case, the former approach causes a failure in glXMakeCurrent, while the latter succeeds. This could indicate a bug in OpenTK.


  • Use apitrace to log the command stream being delivered to the driver. This might help identify the issue.
  • Use the SDL2 backend by installing libsdl2 using your package manager, or compiling it yourself. If this succeeds, then the bug lies somewhere in OpenTK; if this fails, then this might be a driver issue.
Rhedox's picture

GL_ARB_create_context is supported by the server and the client.
I installed a package called "libsdl2-2.0-0" using Ubuntu Software Center and I still get the error.
Maybe I've done something wrong in my project. I don't have an awful lot of experience in Linux (in fact I'm a beginner). And yes I added the dll.config file to my project and made MonoDevelop copy it.

Heres a screenshot of the apitrace: IMGUR apitrace screenshot
I don't get anything from this but I certainly hope one of you guys does.

More detail on glX_create_context:
8) glXCreateContext(dpy = 0x1b80b50, vis = [{visual = 0x1badb28, visualid = 39, screen = 0, depth = 24, c_class = 4, red_mask = 16711680, green_mask = 65280, blue_mask = 255, colormap_size = 256, bits_per_rgb = 8}], shareList = NULL, direct = True) = 0x1c2f520

It doesn't do glX_ARB_create_context so I guess it's an OpenTK bug.

the Fiddler's picture

Weird, there are 4 calls to glXCreateContext and 1 call to glXCreateContextAttribsARB (that's GLX_ARB_create_context). This does not look right.

Did you install OpenTK from the Ubuntu repository, or did you download it from this website? (The former does not support SDL2 and has various other bugs.)

If possible, try building a debug version of OpenTK. This will print extra diagnostic information in the "Application Output" window of MonoDevelop, including the backend in use (SDL2 or native) and warnings about potential problems.

I'll try to see if I can install Ubuntu on my laptop to test (I am currently relying on virtual machines for Linux.)

Rhedox's picture

I installed it using the version 1.1 windows installer. Then I added a reference to the OpenTK.dll and copied the OpenTK.dll.config. (Multiboot)
I even downloaded it again under Ubuntu and I still get the same error.

the Fiddler's picture

Tracking this here: https://github.com/opentk/opentk/issues/108

Can you try to request a 3.3 context with GraphicsContextFlags.Default instead of ForwardCompatible? I'll have to install Ubuntu on an external disk to trace this, but until then the more information we have about the error the better our chances to understand what is going wrong where.

As a workaround, you can request a 1.0 compatibility context. This will still give you a 4.4 context on Linux and Windows (or the maximum supported by the drivers). The only downside is that this will give you only 2.1 on a Mac, so you'd have to special-case it:

// Workaround for OpenTK issue #108
Game game;
if (OpenTK.Configuration.RunningOnMac)
    game = new Game(/* parameters */, 3, 2, GraphicsContextFlags.ForwardCompatible);
    game = new Game(/* parameters */, 1, 0, GraphicsContextFlags.Default);
Rhedox's picture

I tried that already. Doesn't work.
BTW just create a live stick.

Rhedox's picture

I still have the exact same bug in the opentk-2014-05-19 build.

the Fiddler's picture

I haven't been able to reproduce this on my native Arch installation + binary nvidia drivers (650M GPU). I am also not able to reproduce this with the nouveau, intel or mesa (software) drivers on the same installation, or on Arch, OpenSUSE or Ubuntu inside Virtualbox (either VB or mesa drivers.)

Can you try using a GraphicsMode with a different depth to see whether that helps? For instance:

Game game = new Game(1280, 720, new GraphicsMode(32, 24, 0, 0), ...)


Game game = new Game(1280, 720, new GraphicsMode(24, 24, 0, 0), ...)

This issue appears to be caused by a mismatch between the GLX visual of the GLX context and the native X11 window. In theory, this should never happen. In practice, GLX/X11 can be very finicky.

I'll see if I can dig something up in the documentation.