我正在尝试使用 gtk# 和 opengl 编写一个简单而基本的建模程序。为了能够同时使用 gtk gui 和 opengl,我使用了 glwidget。最近我在同一个 vbox 中同时拥有一个菜单栏和一个 glwidget 时遇到了问题(它们在不同的插槽中,但在同一个 vbox 中)。这是我的代码:
//MainWindow.cs
using System;
using Gtk;
using CubeGameModeler;
using OpenTK;
using OpenTK.Graphics.OpenGL;
using GLib;
public partial class MainWindow: Gtk.Window
{
public MainWindow (): base (Gtk.WindowType.Toplevel)
{
Build ();
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
protected void OnExit (object sender, EventArgs e)
{
Application.Quit ();
}
protected void OnSaveAs (object sender, EventArgs e)
{
SaveWindow savewindow = new SaveWindow ();
savewindow.Show ();
}
protected void OnSettings (object sender, EventArgs e)
{
SettingsWindow settingswindow = new SettingsWindow ();
settingswindow.Show ();
}
protected void OnAbout (object sender, EventArgs e)
{
AboutWindow aboutwindow = new AboutWindow ();
aboutwindow.Show ();
}
protected void OnOpen (object sender, EventArgs e)
{
OpenWindow openwindow = new OpenWindow ();
openwindow.Show ();
}
protected void OnHelp (object sender, EventArgs e)
{
HelpWindow helpwindow = new HelpWindow ();
helpwindow.Show ();
}
protected void glwidget2_RenderFrame (object sender, EventArgs e)
{
GL.Viewport (0, 0, 100, 100);
GL.ClearColor (0.5f, 0.5f, 1.0f, 1.0f);
GL.Clear (ClearBufferMask.ColorBufferBit);
GL.MatrixMode (MatrixMode.Modelview);
GL.LoadIdentity ();
}
}
这是我的 MainWindow.cs 类中的代码。我还不担心opengl渲染,我只是想让窗口保持打开状态超过一秒钟。我不知道这是否是一个错误,或者它是否与我蹩脚的笔记本电脑有关。我在 Debian Wheezy i386 上使用 MonoDevelop。当我尝试运行该程序时,它会打开片刻然后关闭。当我查看应用程序输出时,它是这样说的:
Loaded assembly: /home/mprogrammer/Documents/Monodevelop_Projects/CubeGameModeler/CubeGameModeler/bin/Debug/CubeGameModeler.exe
Loaded assembly: /usr/lib/mono/gac/gtk-sharp/2.12.0.0__35e10195dab3c99f/gtk-sharp.dll [External]
Loaded assembly: /usr/lib/mono/gac/glib-sharp/2.12.0.0__35e10195dab3c99f/glib-sharp.dll [External]
Loaded assembly: /usr/lib/mono/gac/atk-sharp/2.12.0.0__35e10195dab3c99f/atk-sharp.dll [External]
Loaded assembly: /usr/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll [External]
Loaded assembly: /usr/lib/mono/gac/gdk-sharp/2.12.0.0__35e10195dab3c99f/gdk-sharp.dll [External]
Loaded assembly: /usr/lib/mono/gac/Mono.Posix/4.0.0.0__0738eb9f132ed756/Mono.Posix.dll [External]
Loaded assembly: /home/mprogrammer/Documents/Monodevelop_Projects/CubeGameModeler/CubeGameModeler/bin/Debug/OpenTK.dll [External]
Loaded assembly: /usr/lib/mono/gac/System.Drawing/4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll [External]
Stacktrace:
at (wrapper managed-to-native) Gtk.Application.gtk_main () <IL 0x00022, 0xffffffff>
at Gtk.Application.Run () <IL 0x00000, 0x0001f>
at CubeGameModeler.MainClass.Main (string[]) [0x00011] in /home/mprogrammer/Documents/Monodevelop_Projects/CubeGameModeler/CubeGameModeler/Main.cs:13
at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>
Native stacktrace:
/usr/bin/mono() [0x80e863d]
/usr/bin/mono() [0x8128bac]
/usr/bin/mono() [0x8064d1f]
[0xb76f240c]
/lib/i386-linux-gnu/i686/cmov/libpthread.so.0(__pthread_mutex_lock+0x1d) [0xb769618d]
/usr/lib/i386-linux-gnu/libX11.so.6(+0x2999d) [0xb64d599d]
[0x156]
Debug info from gdb:
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
我通过反复试验确定问题出在菜单栏上,因为如果我将其留在窗口上,但使其不可见,则 glwidget 没有问题,程序继续运行。
如果需要更多信息,请告诉我。