ITel's picture

Problem with context & GLWidget in Ubuntu 9.04

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


public MainWindow (): base (Gtk.WindowType.Toplevel)
	Build ();
	GLControl gc = new GLControl();

And now application crashed with:

  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]
	/usr/lib/ [0xb67e121f]
	/usr/lib/ [0xb67f7dce]
	/usr/lib/ [0xb67d745b]
	/usr/lib/ [0xb675d978]
	/usr/lib/ [0xb675dca4]
	/usr/lib/ [0xb675e5bc]
	/usr/lib/ [0xb675ed6a]
	/usr/lib/ [0xb693eeb1]
	/usr/lib/ [0xb6912923]
	/usr/lib/ [0xb691eb60]
	/usr/lib/ [0xb6912923]
	/usr/lib/ [0xb692b9ee]
	/usr/lib/ [0xb6ab755e]
	/usr/lib/ [0xb692be95]
	/usr/lib/ [0xb692c4af]
	/usr/lib/ [0xb692c4db]
	/usr/lib/ [0xb690f8fb]
	/usr/lib/ [0xb7ef8c81]
	/usr/lib/ [0xb7efab88]
	/usr/lib/ [0xb7efe0eb]
	/usr/lib/ [0xb7efe5ba]
	/usr/lib/ [0xb6ab77d9]
	/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/ [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..


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

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?

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

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


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.