簡體   English   中英

C#單聲道p /調用失敗

[英]C# mono p/invoke failure

最近,我嘗試在mono(用於Linux平台的.NET)中使用p / invoke編寫一個簡單的OpenGL應用程序,以了解其在C#上的工作方式(我已經在Windows上成功完成了此工作)。 我聽說過tao框架,但是我不想要簡單的“ hello world”之類的程序的所有內容。

我剛開始就卡住了。 我p /調用了一些GL函數,以查看它們是否起作用。 我立即調用glClearColor和glClear來查看它是否設置了glGetError(由於那時還沒有初始化opengl)。

而不是調用函數,它只是崩潰並轉儲以下堆棧跟蹤和其他debuginfo。 沒有異常被拋出。

堆棧跟蹤:

  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>

glClearColor的簽名是:

//gllibname="opengl32.dll" --> mapped to libGL.so
[DllImport(gllibname)]

public static extern void glClearColor(float red, float green, float blue, float alpha);

C規范是:

void glClearColor( GLclampf red,GLclampf green,GLclampf blue,GLclampf alpha );

GLclampf是浮動的,因為我在標題中看到了它的聲明。

您可以使用gdb運行該程序,並准確查看SEGV發生的位置(有關說明,請參見mono wiki )。

可能的原因是其他一些不正確的p / invoke聲明,並在代碼中調用了已損壞的內存,因此稍后會導致崩潰。

我發現了。 在執行p / invoke時,我使用了錯誤的函數簽名。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM