yiannis's picture

GLWidget fails creating context

Hi,

I hope this is the place to post for help regarding GLWidget.
When running the GLWidget test project, the application terminates with this error:

The program 'GLWidgetTest' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadMatch (invalid parameter attributes)'.
  (Details: serial 213 error_code 8 request_code 128 minor_code 5)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the --sync command line
   option to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)

This error occurs in GLWidget.cs line 212 (graphicsContext.MakeCurrent(windowInfo)).
Any ideas or pointers on what to look for?

Thanks in advance for all the help.

PS: My environment is:
Ubuntu 10.04 32 bit
Mono 2.6.7
GTK# 2.12.9
MonoDevelop 2.4
OpenTK svn trunk (have also tried with 1.0.0-rc1)


Comments

Comment viewing options

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

I just tested on a virtual machine. I am not getting a crash when running, but I do get this error when calling new GraphicsMode:
OpenGL Warning: XGetVisualInfo returned 0 visuals for....

What video card are you running? Is hardware acceleration enabled?

You may want to try explicitly setting a ColorBPP on the GLWidget to maybe 24 or 16 and see if that works....

For Reference:

GraphicsMode graphicsMode = new GraphicsMode(colorBufferColorFormat, DepthBPP, StencilBPP, Samples, accumulationColorFormat, buffers, Stereo);
IntPtr display = gdk_x11_display_get_xdisplay(Display.Handle);
int screen = Screen.Number;
IntPtr windowHandle = gdk_x11_drawable_get_xid(GdkWindow.Handle);
IntPtr rootWindow = gdk_x11_drawable_get_xid(RootWindow.Handle);
 
IntPtr visualInfo;
if (graphicsMode.Index.HasValue)
{
	XVisualInfo info = new XVisualInfo();
	info.VisualID = graphicsMode.Index.Value;
	int dummy;
	visualInfo = XGetVisualInfo(display, XVisualInfoMask.ID, ref info, out dummy);
}
else
{
	visualInfo = GetVisualInfo(display);
}
 
windowInfo = OpenTK.Platform.Utilities.CreateX11WindowInfo(display, screen, windowHandle, rootWindow, visualInfo);
XFree(visualInfo);
 
graphicsContext = new GraphicsContext(graphicsMode, windowInfo, GlVersionMajor, GlVersionMinor, graphicsContextFlags);
graphicsContext.MakeCurrent(windowInfo);
yiannis's picture

Thanks for the reply JTalton.
My GPU is GeForce 9600M GS and, yes, hardware acceleration is enabled (i.e. the card works just fine with other programs I 've written (in C++)).
Anyway, I have enabled tracing and here's a more detailed log of what happens:

Size: 2304
System:
    Linux
Initializing threaded X11: 1.
Display connection: 150372880, Screen count: 1
Detected configuration: Linux / Mono
Initializing threaded X: success.
Creating default GraphicsMode (24, 16, 0, 0, 0, 2, False).
Bits per pixel: 32
Depth: 16
Display: 150372880, Screen: 0, RootWindow: 346
Getting FB config.
Bits per pixel: 32
Depth: 16
Falling back to glXChooseVisual.
Creating GraphicsContext.
    GraphicsMode: Index: 40, Color: 32 (8888), Depth: 24, Stencil: 0, Samples: 0, Accum: 64 (16161616), Buffers: 2, Stereo: False
    IWindowInfo: X11.WindowInfo: Display 149195032, Screen 0, Handle 92274710, Parent: (null)
    GraphicsContextFlags: Default
    Requested version: 1.0
    Creating X11GLContext context: direct, not shared... 
    Creating temporary context to load GLX extensions.
    Loading extensions for OpenTK.Platform.X11.Glx... 2 extensions loaded in 3.4711 ms.
    Using legacy context creation... Context created (id: 151747816).
Making context 151747816 current on thread 1 (Display: 149195032, Screen: 0, Window: 92274710)...
The program 'GLWidgetTest' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadMatch (invalid parameter attributes)'.
  (Details: serial 213 error_code 8 request_code 128 minor_code 5)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the --sync command line
   option to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)
JTalton's picture

At one point this was working, so something changed, either in Ubuntu, GTK , or OpenTK. If I can find some time, I'll try to figure out what is going on.

yiannis's picture
JTalton wrote:

At one point this was working, so something changed, either in Ubuntu, GTK , or OpenTK. If I can find some time, I'll try to figure out what is going on.

Thanks a lot for the help.

After looking at the code in OpenTK (X11GLContext.cs), I tried requesting a GL context version 3.0 and it worked. This means that the context was successfully created only when the code called GLX_ARB_create_context.
Looks like Glx.CreateContext() (the call made for contexts <3.0) was the culprit in my case, if anyone wants to investigate more...