title: C# mono p/invoke failure
body: <p>Recently I tried to use p/invoke in mono (.NET for Linux platform) to write a simple OpenGL application to find out how it works on C# (I've already sucessfully done it on windows). I heard about the tao framework, but I don't want everything for a simple "hello world" like program.</p>
  
  <p>I just stucked at the start. I p/invoked some GL functions to see if they work. I immediately called glClearColor and glClear to see whether it sets glGetError or not (due to opengl haven't been initialized at all at that point). </p>
  
  <p>Instead of calling the function it just crashes and dumps the following stack trace and other debuginfo. No exception is thrown.</p>
  
  <p>Stacktrace:</p>
  
  <pre><code>  at (wrapper managed-to-native) Calmarius.OGL.OpenGLLibrary.glClearColor (single,single,single,single) &lt;0x00004&gt;
    at (wrapper managed-to-native) Calmarius.OGL.OpenGLLibrary.glClearColor (single,single,single,single) &lt;0xffffffff&gt;
    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&amp;) &lt;0x000b0&gt;
    at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message&amp;) &lt;0x001e2&gt;
    at System.Windows.Forms.ScrollableControl.WndProc (System.Windows.Forms.Message&amp;) &lt;0x0000d&gt;
    at System.Windows.Forms.ContainerControl.WndProc (System.Windows.Forms.Message&amp;) &lt;0x00054&gt;
    at System.Windows.Forms.Form.WndProc (System.Windows.Forms.Message&amp;) &lt;0x001da&gt;
    at ControlWindowTarget.OnMessage (System.Windows.Forms.Message&amp;) &lt;0x00014&gt;
    at ControlNativeWindow.WndProc (System.Windows.Forms.Message&amp;) &lt;0x00022&gt;
    at System.Windows.Forms.NativeWindow.WndProc (intptr,System.Windows.Forms.Msg,intptr,intptr) &lt;0x001b7&gt;
    at System.Windows.Forms.XplatUIX11.DispatchMessage (System.Windows.Forms.MSG&amp;) &lt;0x00016&gt;
    at System.Windows.Forms.XplatUI.DispatchMessage (System.Windows.Forms.MSG&amp;) &lt;0x00015&gt;
    at System.Windows.Forms.Application.RunLoop (bool,System.Windows.Forms.ApplicationContext) &lt;0x00997&gt;
    at System.Windows.Forms.Application.Run (System.Windows.Forms.ApplicationContext) &lt;0x0006a&gt;
    at System.Windows.Forms.Application.Run (System.Windows.Forms.Form) &lt;0x00025&gt;
    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) &lt;0xffffffff&gt;
  </code></pre>
  
  <p>The signature for glClearColor is:</p>
  
  <pre><code>//gllibname="opengl32.dll" --&gt; mapped to libGL.so
  [DllImport(gllibname)]
  
  public static extern void glClearColor(float red, float green, float blue, float alpha);
  </code></pre>
  
  <p>C specification is:</p>
  
  <pre><code>void glClearColor( GLclampf red,GLclampf green,GLclampf blue,GLclampf alpha );
  </code></pre>
  
  <p>GLclampf is float as I saw its declaration in the header.</p>