VeliV's picture

Mac OSX applications fail when setting up GLControl

Project:The Open Toolkit library
Version:1.0-beta-1
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

The line 4th line on the following code causes a crash on Mac OSX

using System;
using System.Windows.Forms;
 
public class HelloWorld : Form
{
  OpenTK.GLControl glControl = new OpenTK.GLControl();
 
  static public void Main()
  {
    Application.Run(new HelloWorld());
  }
 
  public HelloWorld()
  {
    Text = "Hello World";
 
  }
}

Here is the output:

System.InvalidCastException: Cannot cast from source type to destination type.
  at OpenTK.Platform.MacOS.AglContext..ctor (OpenTK.Graphics.GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext) [0x00000] 
  at OpenTK.Platform.MacOS.MacOSFactory.CreateGLContext (OpenTK.Graphics.GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, Boolean directRendering, Int32 major, Int32 minor, GraphicsContextFlags flags) [0x00000] 
  at OpenTK.Graphics.GraphicsContext..ctor (OpenTK.Graphics.GraphicsMode mode, IWindowInfo window, Int32 major, Int32 minor, GraphicsContextFlags flags) [0x00000] 
  at OpenTK.CarbonGLControl.CreateContext (Int32 major, Int32 minor, GraphicsContextFlags flags) [0x00000] 
  at OpenTK.GLControl.OnHandleCreated (System.EventArgs e) [0x00000] 
  at System.Windows.Forms.Control.WmCreate (System.Windows.Forms.Message& m) [0x00000] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs:5759 
  at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message& m) [0x001e4] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs:5397 
  at System.Windows.Forms.ScrollableControl.WndProc (System.Windows.Forms.Message& m) [0x00000] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ScrollableControl.cs:807 
  at System.Windows.Forms.ContainerControl.WndProc (System.Windows.Forms.Message& m) [0x0003d] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ContainerControl.cs:642 
  at System.Windows.Forms.UserControl.WndProc (System.Windows.Forms.Message& m) [0x00037] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/UserControl.cs:150 
  at System.Windows.Forms.Control+ControlWindowTarget.OnMessage (System.Windows.Forms.Message& m) [0x00000] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs:234 
  at System.Windows.Forms.Control+ControlNativeWindow.WndProc (System.Windows.Forms.Message& m) [0x00000] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs:215 
  at System.Windows.Forms.NativeWindow.WndProc (IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam) [0x00085] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/NativeWindow.cs:242

Using Mac OSX Snow Leopard, latest mono and revision 2465 from the SVN.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

#1

Thanks.

Please double check that the OpenTK version number reads 0.9.9-4, not 0.9.9-3 (I get bitten by this very often, sometimes the IDE doesn't actually replace the reference).

It would also help to run the test case with a debug version of OpenTK.dll (I've posted some instructions here).

VeliV's picture

#2

Yah, the ref wasnt updated but now it is. Here is the new output:

Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for OpenTK.DisplayDevice ---> System.TypeInitializationException: An exception was thrown by the type initializer for OpenTK.Platform.X11.X11XrandrDisplayDevice ---> System.DllNotFoundException: libXrandr.so.2
  at (wrapper managed-to-native) OpenTK.Platform.X11.Functions:XRRTimes (intptr,int,intptr&)
  at OpenTK.Platform.X11.X11XrandrDisplayDevice..cctor () [0x00193] in /Users/VeliV/Projects/OpenTK/Source/OpenTK/Platform/X11/X11XrandrDisplayDevice.cs:91 
  --- End of inner exception stack trace ---
  at OpenTK.Platform.X11.X11Factory.CreateDisplayDeviceDriver () [0x00000] in /Users/VeliV/Projects/OpenTK/Source/OpenTK/AutoGeneratedAttribute.cs:1 
  at OpenTK.DisplayDevice..cctor () [0x00014] in /Users/VeliV/Projects/OpenTK/Source/OpenTK/DisplayDevice.cs:52 
  --- End of inner exception stack trace ---
  at OpenTK.Graphics.GraphicsMode.get_Default () [0x00016] in /Users/VeliV/Projects/OpenTK/Source/OpenTK/Graphics/GraphicsMode.cs:310 
  at OpenTK.GLControl..ctor () [0x00000] in /Users/VeliV/Projects/OpenTK/Source/GLControl/CarbonGLControl.cs:1 
  at (wrapper remoting-invoke-with-check) OpenTK.GLControl:.ctor ()
  at HelloWorld..ctor () [0x00000] in /Users/VeliV/Projects/OdinGI/OdinGI/Main.cs:1 
  at (wrapper remoting-invoke-with-check) HelloWorld:.ctor ()
  at HelloWorld.Main () [0x00000] in /Users/VeliV/Projects/OdinGI/OdinGI/Main.cs:1 
 
The application was terminated by a signal: SIGHUP
the Fiddler's picture

#3

Thanks, this is interesting. It seems that the platform detection code has gone awry and it's trying to use X11 instead of Carbon/Quartz. Do you have an X server installed, by any chance?

Edit: I have modified the platform factory to prefer the native implementation over the X based driver when both are detected. Can you please update to rev. 2466 and try again?

VeliV's picture

#4

Hmm. dunno what you mean :) I don't think I have X Server installed, if it didn't come with the OS. Do you have a link to X Server site so I can check and perhaps install it?

the Fiddler's picture

#5

Apple has some documentation here. Mac OS X comes with an X server by default, by you have to install it manually.

Two possibilities

  • OpenTK has broken detection code and thinks there's an X server when there really isn't
  • There actually *is* an X server and OpenTK tries to use it instead of the native APIs (which means OpenTK is still broken, but in a different way)

Since 0.9.9-3 QuickStart worked, this is a bug that was introduced between 0.9.9-3 and 0.9.9-4 (I did touch the platform detection code, which means I probably broke it). Still, it would be helpful if you could check whether SVN rev. 2466 starts up correctly.

VeliV's picture

#6

Nah, dont have X server installed.

SVN up, compile, and re run. Here is the output

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
  at OpenTK.Graphics.GraphicsMode.get_Default () [0x00016] in /Users/VeliV/Projects/OpenTK/Source/OpenTK/Graphics/GraphicsMode.cs:310 
  at OpenTK.GLControl..ctor () [0x00000] in /Users/VeliV/Projects/OpenTK/Source/GLControl/CarbonGLControl.cs:1 
  at (wrapper remoting-invoke-with-check) OpenTK.GLControl:.ctor ()
  at HelloWorld..ctor () [0x00000] in /Users/VeliV/Projects/OdinGI/OdinGI/Main.cs:1 
  at (wrapper remoting-invoke-with-check) HelloWorld:.ctor ()
  at HelloWorld.Main () [0x00000] in /Users/VeliV/Projects/OdinGI/OdinGI/Main.cs:1 
 
The application was terminated by a signal: SIGHUP

SOmething seems to have changed ;)

the Fiddler's picture

#7

Status:open» in progress

Another careless bug introduced today - the primary DisplayDevice was not set under some circumstances. Can you please test rev. 2467?

(Fixing bugs, one issue at a time!)

VeliV's picture

#8

Success, at least partly.

This script now runs:

using System;
using System.Windows.Forms;
using OpenTK;
using OpenTK.Graphics;
 
public class HelloWorld : Form
{
  OpenTK.GLControl glControl = new OpenTK.GLControl();
 
  static public void Main()
  {
    Application.Run(new HelloWorld());
  }
 
  public HelloWorld()
  {
    Text = "Hello World";
	Height = 600;
	Width = 800;
	CenterToScreen();
  }
}

But, this doesn't :P

using System;
using System.Windows.Forms;
using OpenTK;
using OpenTK.Graphics;
 
public class HelloWorld : Form
{
  OpenTK.GLControl glControl = new OpenTK.GLControl();
 
  static public void Main()
  {
    Application.Run(new HelloWorld());
  }
 
  public HelloWorld()
  {
    Text = "Hello World";
	Height = 600;
	Width = 800;
	CenterToScreen();
 
	glControl.Dock = DockStyle.Fill; // I hope I got this right     
    glControl.Paint += (sender, e) =>
    {
       glControl.SwapBuffers();
    };
 
	Controls.Add(glControl);
  }
}

Seems to crash at Controls.Add(glControl); . Here is the output:

Stacktrace:
 
  at (wrapper managed-to-native) OpenTK.X11GLControl.XGetVisualInfoInternal (intptr,intptr,OpenTK.X11GLControl/XVisualInfo&,int&) <0x00004>
  at (wrapper managed-to-native) OpenTK.X11GLControl.XGetVisualInfoInternal (intptr,intptr,OpenTK.X11GLControl/XVisualInfo&,int&) <0xffffffff>
  at OpenTK.X11GLControl.XGetVisualInfo (intptr,int,OpenTK.X11GLControl/XVisualInfo&,int&) [0x00000] in /Users/VeliV/Projects/OpenTK/Source/GLControl/X11GLControl.cs:32
  at OpenTK.X11GLControl..ctor (OpenTK.Graphics.GraphicsMode,System.Windows.Forms.Control) [0x000c3] in /Users/VeliV/Projects/OpenTK/Source/GLControl/X11GLControl.cs:94
  at OpenTK.GLControlFactory.CreateGLControl (OpenTK.Graphics.GraphicsMode,System.Windows.Forms.Control) [0x0003e] in /Users/VeliV/Projects/OpenTK/Source/GLControl/GLControlFactory.cs:47
  at OpenTK.GLControl.OnHandleCreated (System.EventArgs) [0x0004c] in /Users/VeliV/Projects/OpenTK/Source/GLControl/GLControl.cs:145
  at System.Windows.Forms.Control.WmCreate (System.Windows.Forms.Message&) [0x00000] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs:5759
  at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message&) [0x001e4] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs:5397
  at System.Windows.Forms.ScrollableControl.WndProc (System.Windows.Forms.Message&) [0x00000] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ScrollableControl.cs:807
  at System.Windows.Forms.ContainerControl.WndProc (System.Windows.Forms.Message&) [0x0003d] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ContainerControl.cs:642
  at System.Windows.Forms.UserControl.WndProc (System.Windows.Forms.Message&) [0x00037] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/UserControl.cs:150
  at System.Windows.Forms.Control/ControlWindowTarget.OnMessage (System.Windows.Forms.Message&) [0x00000] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs:234
  at System.Windows.Forms.Control/ControlNativeWindow.WndProc (System.Windows.Forms.Message&) [0x00000] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs:215
  at System.Windows.Forms.NativeWindow.WndProc (intptr,System.Windows.Forms.Msg,intptr,intptr) [0x00085] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/NativeWindow.cs:242
  at System.Windows.Forms.XplatUICarbon.SendMessage (intptr,System.Windows.Forms.Msg,intptr,intptr) [0x00000] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUICarbon.cs:1693
  at System.Windows.Forms.XplatUICarbon.CreateWindow (System.Windows.Forms.CreateParams) [0x004d1] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUICarbon.cs:1039
  at System.Windows.Forms.XplatUI.CreateWindow (System.Windows.Forms.CreateParams) [0x00000] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUI.cs:504
  at System.Windows.Forms.NativeWindow.CreateHandle (System.Windows.Forms.CreateParams) [0x0000c] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/NativeWindow.cs:167
  at System.Windows.Forms.Control.CreateHandle () [0x0003a] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs:4504
  at System.Windows.Forms.Control.CreateControl () [0x0004b] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs:3781
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control.CreateControl () <0xffffffff>
  at System.Windows.Forms.Control.CreateControl () [0x00090] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs:3793
  at System.Windows.Forms.Control.SetVisibleCore (bool) [0x00043] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs:5075
  at System.Windows.Forms.Form.SetVisibleCore (bool) [0x0007b] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs:2451
  at System.Windows.Forms.Control.set_Visible (bool) [0x0000c] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs:3433
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control.set_Visible (bool) <0xffffffff>
  at System.Windows.Forms.Application.RunLoop (bool,System.Windows.Forms.ApplicationContext) [0x00059] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Application.cs:862
  at System.Windows.Forms.Application.Run (System.Windows.Forms.ApplicationContext) [0x00014] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Application.cs:761
  at System.Windows.Forms.Application.Run (System.Windows.Forms.Form) [0x00000] in /private/tmp/monobuild/build/BUILD/mono-2.4.2.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Application.cs:740
  at HelloWorld.Main () [0x00000] in /Users/VeliV/Projects/OdinGI/OdinGI/Main.cs:12
  at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) <0xffffffff>
The application was terminated by a signal: SIGABRT

Fun fun. BTW, I need to go now, but I am usually on the IRC as well if you'd find that faster palce to test stuff.

the Fiddler's picture

#9

Status:in progress» in progress (review)

Thanks, this was the same issue as above, just in a different place (OpenTK.GLControl.dll). Fixed in rev. 2468.

It seems that the MacOS port has bitrotted more than I thought. We may have to do some debugging sessions like this to get it back to speed. :)

kanato's picture

#10

I was looking into this.. Mac OS Leopard and beyond have X11 installed by default, and the static constructor starts off by trying to detect X11, which succeeds on Mac OS, and then it detects the Kernel and ends up with both runningOnX11 and runningOnMacOS true. Then later when the factory is instantiated, we have if (windows) else if (X11) {} else if (MacOS) which will instantiate the X11 factory and try to go from there. I was messing around with detecting the kernel first then checking for X11 if runningOnMacOS is false, but there seems to be more to the issue than that.

PS. I just bought Snow Leopard last night.. I can't believe it was only $29. Now I am getting my mac up to date.