C#mono p/调用失败
最近,我尝试在mono(.NET for Linux平台)中使用p/invoke编写一个简单的OpenGL应用程序,以了解它在C#上的工作原理(我已经在windows上成功地完成了)。我听说过tao框架,但我不希望所有的东西都像一个简单的“helloworld”程序 我刚开始就结巴了。我调用了一些GL函数以查看它们是否工作。我立即调用了glClearColor和glClear,查看它是否设置了glGetError(因为opengl当时还没有初始化) 它没有调用函数,而是崩溃并转储以下堆栈跟踪和其他debuginfo。没有抛出异常 堆栈跟踪:C#mono p/调用失败,c#,mono,pinvoke,segmentation-fault,C#,Mono,Pinvoke,Segmentation Fault,最近,我尝试在mono(.NET for Linux平台)中使用p/invoke编写一个简单的OpenGL应用程序,以了解它在C#上的工作原理(我已经在windows上成功地完成了)。我听说过tao框架,但我不希望所有的东西都像一个简单的“helloworld”程序 我刚开始就结巴了。我调用了一些GL函数以查看它们是否工作。我立即调用了glClearColor和glClear,查看它是否设置了glGetError(因为opengl当时还没有初始化) 它没有调用函数,而是崩溃并转储以下堆栈跟踪和其
at (wrapper managed-to-native) Calmarius.OGL.OpenGLLibrary.glClearColor (single,single,single,single) <0x00004>
at (wrapper managed-to-native) Calmarius.OGL.OpenGLLibrary.glClearColor (single,single,single,single) <0xffffffff>
at Calmarius.RTS.GameForm.OnPaint (System.Windows.Forms.PaintEventArgs) [0x00000] in /home/calmarius/Development/csharp/RTS/RTS/Form1.cs:60
at System.Windows.Forms.Control.WmPaint (System.Windows.Forms.Message&) <0x000b0>
at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message&) <0x001e2>
at System.Windows.Forms.ScrollableControl.WndProc (System.Windows.Forms.Message&) <0x0000d>
at System.Windows.Forms.ContainerControl.WndProc (System.Windows.Forms.Message&) <0x00054>
at System.Windows.Forms.Form.WndProc (System.Windows.Forms.Message&) <0x001da>
at ControlWindowTarget.OnMessage (System.Windows.Forms.Message&) <0x00014>
at ControlNativeWindow.WndProc (System.Windows.Forms.Message&) <0x00022>
at System.Windows.Forms.NativeWindow.WndProc (intptr,System.Windows.Forms.Msg,intptr,intptr) <0x001b7>
at System.Windows.Forms.XplatUIX11.DispatchMessage (System.Windows.Forms.MSG&) <0x00016>
at System.Windows.Forms.XplatUI.DispatchMessage (System.Windows.Forms.MSG&) <0x00015>
at System.Windows.Forms.Application.RunLoop (bool,System.Windows.Forms.ApplicationContext) <0x00997>
at System.Windows.Forms.Application.Run (System.Windows.Forms.ApplicationContext) <0x0006a>
at System.Windows.Forms.Application.Run (System.Windows.Forms.Form) <0x00025>
at Calmarius.RTS.Program.Main () [0x0000b] in /home/calmarius/Development/csharp/RTS/RTS/Program.cs:19
at (wrapper runtime-invoke) System.Object.runtime_invoke_void (object,intptr,intptr,intptr) <0xffffffff>
C规格为:
void glClearColor( GLclampf red,GLclampf green,GLclampf blue,GLclampf alpha );
GLclampf是float,正如我在标题中看到它的声明一样。您可以使用gdb运行程序,并查看SEGV发生的确切位置(有关说明,请参阅mono)
一个可能的原因是其他一些不正确的p/invoke声明和代码中的调用损坏了内存,因此稍后会发生崩溃。我发现了它。我在执行p/invoke时使用了错误的函数签名 @ps:Firefox 3.0仍然支持我。你应该添加你在C#中声明方法的方式,以及你正在pinvoking的C方法的签名。你得到的异常消息和类型是什么?没有异常消息。这个程序只是因为SIGSEGV信号而崩溃。
void glClearColor( GLclampf red,GLclampf green,GLclampf blue,GLclampf alpha );