ITel's picture

Problem with context & GLWidget in Ubuntu 9.04

Hello!
In Ubuntu 8.10, I use GLControl to make a context for GLWidget, but now, in Ubuntu 9.04 it doesn't work!

example:

...
public MainWindow (): base (Gtk.WindowType.Toplevel)
{
	Build ();
	GLControl gc = new GLControl();
	GL.LoadAll();
	Glu.LoadAll();
	gc.Dispose();
}
...

And now application crashed with:

Stacktrace:
 
  at (wrapper managed-to-native) Gtk.Application.gtk_main () <0x00004>
  at (wrapper managed-to-native) Gtk.Application.gtk_main () <0xffffffff>
  at Gtk.Application.Run () <0x00007>
  at Test.MainClass.Main (string[]) [0x00011] in .../Test/Test/Main.cs:16
  at (wrapper runtime-invoke) Test.MainClass.runtime_invoke_void_string[] (object,intptr,intptr,intptr) <0xffffffff>
 
Native stacktrace:
 
	/usr/bin/mono [0x806d944]
	/usr/bin/mono [0x808616b]
	[0xb7f8e410]
	/usr/lib/libX11.so.6 [0xb67e121f]
	/usr/lib/libX11.so.6(XrmQGetResource+0x3e) [0xb67f7dce]
	/usr/lib/libX11.so.6(XGetDefault+0xcb) [0xb67d745b]
	/usr/lib/libcairo.so.2 [0xb675d978]
	/usr/lib/libcairo.so.2 [0xb675dca4]
	/usr/lib/libcairo.so.2 [0xb675e5bc]
	/usr/lib/libcairo.so.2(cairo_xlib_surface_create+0x10a) [0xb675ed6a]
	/usr/lib/libgdk-x11-2.0.so.0 [0xb693eeb1]
	/usr/lib/libgdk-x11-2.0.so.0 [0xb6912923]
	/usr/lib/libgdk-x11-2.0.so.0 [0xb691eb60]
	/usr/lib/libgdk-x11-2.0.so.0 [0xb6912923]
	/usr/lib/libgdk-x11-2.0.so.0(gdk_window_begin_paint_region+0x11e) [0xb692b9ee]
	/usr/lib/libgtk-x11-2.0.so.0(gtk_main_do_event+0x51e) [0xb6ab755e]
	/usr/lib/libgdk-x11-2.0.so.0 [0xb692be95]
	/usr/lib/libgdk-x11-2.0.so.0(gdk_window_process_all_updates+0xff) [0xb692c4af]
	/usr/lib/libgdk-x11-2.0.so.0 [0xb692c4db]
	/usr/lib/libgdk-x11-2.0.so.0 [0xb690f8fb]
	/usr/lib/libglib-2.0.so.0 [0xb7ef8c81]
	/usr/lib/libglib-2.0.so.0(g_main_context_dispatch+0x1e8) [0xb7efab88]
	/usr/lib/libglib-2.0.so.0 [0xb7efe0eb]
	/usr/lib/libglib-2.0.so.0(g_main_loop_run+0x1ca) [0xb7efe5ba]
	/usr/lib/libgtk-x11-2.0.so.0(gtk_main+0xb9) [0xb6ab77d9]
	[0xb48d6ec6]
	[0xb48d6e90]
	[0xb7a05259]
	[0xb7a051b3]
	/usr/bin/mono(mono_runtime_exec_main+0xe5) [0x80bad75]
	/usr/bin/mono(mono_runtime_run_main+0x16b) [0x80bb4eb]
	/usr/bin/mono(mono_main+0x1727) [0x805c917]
	/usr/bin/mono [0x805ac62]
	/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe5) [0xb7d27775]
	/usr/bin/mono [0x805aba1]

Have you any ideas? Or may be there are one more way (more correctly, this way was the simplest for me) to create this context?
P.s: sorry for my English..


Comments

Comment viewing options

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

Does the GLWidget not create its own context? You shouldn't have to use the GLControl at all.

If you are using a recent OpenTK version, you can use GraphicsContext.CreateDummyContext instead. Simply create a dummy context along with the GLWidget and store it as long as the GLWidget exists (i.e. don't Dispose() it). In pseudocode:

Create GLWidget
Create dummy context
GL.LoadAll();
Glu.LoadAll();

The dummy context simply informs OpenTK that an external (i.e. not OpenTK-controlled) OpenGL context exists. You cannot use it to control the external context - swapping buffers, etc, should be done through the GLWidget interface.

Edit: The stacktrace points to a crash inside Mono. Which is the line in your program that triggers this crash? Can you post an isolated test case to confirm this, so we can log a bug to Mono?

ITel's picture

Nothing understand...
Now I create a new gtk# 2.0 project, add references (GLWidget.dll, OpenTK,dll, OpenTK.Utils.dll), and add a GLWidget (by Designer).
If I use (see attachment)
GraphicsContext.CreateDummyContext(); (line 15)
application has crashed with:

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
  at OpenTK.Graphics.GraphicsContext.get_CurrentContext () [0x00000] 
  at OpenTK.Graphics.GL.LoadAll () [0x00000] 
  at MainWindow..ctor () [0x0001e] in /home/ilya/usu/csharp/Test/Test/MainWindow.cs:17 
  at Test.MainClass.Main (System.String[] args) [0x00005] in /home/ilya/usu/csharp/Test/Test/Main.cs:11 
 
The application was terminated by a signal: SIGHUP

But if I use
GLControl gc = new GLControl(); (line 16)
it works! (yesterday I tried to compile the same code and it didn't work)
But now it crashed when I resize window :-) (log in attachment)

Can you edit my solution to taught me how to use the correct context with GLWidget?

AttachmentSize
crash.log10.72 KB
Test.tar_.gz5.95 KB
the Fiddler's picture

The null reference exception looks like an OpenTK bug, could you please enter it into the bug tracker (so it doesn't get lost)?

The GTK crash may be a Mono bug, I will try to reproduce and forward it upstream.

ITel's picture

Ok, wrote a bug report, but may be I do something wrong?

objarni's picture

Pardon my ignorance - What is GLWidget..? Is this some new thing of OpenTK?

ITel's picture

@objarni
it is a gtk# widget for use openGL in gtk# application (analogy GLControl for WinForms)

It was created by JTalton and isn't a part of OpenTK (correct me, if I'm mistaken)
Home page

the Fiddler's picture

Thanks. I can't see anything wrong with your code, but I won't be able to test it until tomorrow.

objarni's picture

@ITel

OK cool, that might prove useful since Winforms is not included in mono.. (simplifying cross-platform deployment of OpenTK-based app')

ITel's picture

@the Fiddler
Thanks for the excellent work!

In OpenTK 0.9.8 GraphicsContext.CreateDummyContext() no longer causes a NullReferenceException, but now I can't create a context :-(
Using GraphicsContext.CreateDummyContext() leads to:

Unhandled Exception: System.InvalidOperationException: No GraphicsContext is current on the calling thread.
  at OpenTK.Graphics.GraphicsContext.CreateDummyContext () [0x00000]

Can you help me?

the Fiddler's picture

As the exception says, you need to create an OpenGL context before calling GraphicsContext.CreateDummyContext. The sequence of steps should look similar to this:

1. Create the OpenGL context
2. Call MakeCurrent on the context
3. Call GraphicsContext.CreateDummyContext() to inform OpenTK about the external context

I have tested OpenTK 0.9.8 with GLWidget on Linux and it works flawlessly on Linux. The only caveat is that you have to call GLWidget.MakeCurrent() before using GraphicsContext.CreateDummyContext().

Note that you cannot actually use this dummy context to control the external context. You have to do this manually - calling IGraphicsContext.SwapBuffers and similar functions won't have any effect.