Exception in WMInput..ctor on Mono
Posted Sunday, 29 June, 2008 - 14:53 by martinsm in
Currently I am succesfuly using OpenTK on Windows using Micrsoft .NET Framework. (great work guys!)
Out of interest I tried running my application also on Mono .NET Framework. And there I am always getting unhandled exception. Here is call stack:
---------------------------
An OpenTK example encountered an error.
---------------------------
System.ArgumentException: Key duplication when adding: 6686626
at System.Collections.Hashtable.PutImpl (object,object,bool) <0x001ac>
at System.Collections.Hashtable.Add (object,object) <0x00012>
at System.Windows.Forms.NativeWindow.AssignHandle (intptr) <0x00074>
at OpenTK.Platform.Windows.WMInput..ctor (OpenTK.Platform.Windows.WinWindowInfo) <0x00181>
at (wrapper remoting-invoke-with-check) OpenTK.Platform.Windows.WMInput..ctor (OpenTK.Platform.Windows.WinWindowInfo) <0x00029>
at OpenTK.Platform.Windows.WinGLNative.OnCreate (System.EventArgs) <0x0007d>
at OpenTK.Platform.Windows.WinGLNative.WndProc (System.Windows.Forms.Message&) <0x003fd>
at System.Windows.Forms.NativeWindow.WndProc (intptr,System.Windows.Forms.Msg,intptr,intptr) <0x0015c>
at System.Windows.Forms.XplatUIWin32.InternalWndProc (intptr,System.Windows.Forms.Msg,intptr,intptr) <0x00046>
at (wrapper native-to-managed) System.Windows.Forms.XplatUIWin32.InternalWndProc (intptr,System.Windows.Forms.Msg,intptr,intptr) <0x00065>
at (wrapper managed-to-native) System.Windows.Forms.XplatUIWin32.Win32CreateWindow (System.Windows.Forms.WindowExStyles,string,string,System.Windows.Forms.WindowStyles,int,int,int,int,intptr,intptr,intptr,intptr) <0x00004>
at System.Windows.Forms.XplatUIWin32.CreateWindow (System.Windows.Forms.CreateParams) <0x0039f>
at System.Windows.Forms.XplatUI.CreateWindow (System.Windows.Forms.CreateParams) <0x00015>
at System.Windows.Forms.NativeWindow.CreateHandle (System.Windows.Forms.CreateParams) <0x00037>
at OpenTK.Platform.Windows.WinGLNative.CreateWindow (int,int,OpenTK.Graphics.GraphicsMode,OpenTK.Graphics.IGraphicsContext&) <0x00109>
at OpenTK.GameWindow..ctor (int,int,OpenTK.Graphics.GraphicsMode,string,OpenTK.GameWindowFlags,OpenTK.Graphics.DisplayDevice) <0x00175>
An OpenTK example encountered an error.
---------------------------
System.ArgumentException: Key duplication when adding: 6686626
at System.Collections.Hashtable.PutImpl (object,object,bool) <0x001ac>
at System.Collections.Hashtable.Add (object,object) <0x00012>
at System.Windows.Forms.NativeWindow.AssignHandle (intptr) <0x00074>
at OpenTK.Platform.Windows.WMInput..ctor (OpenTK.Platform.Windows.WinWindowInfo) <0x00181>
at (wrapper remoting-invoke-with-check) OpenTK.Platform.Windows.WMInput..ctor (OpenTK.Platform.Windows.WinWindowInfo) <0x00029>
at OpenTK.Platform.Windows.WinGLNative.OnCreate (System.EventArgs) <0x0007d>
at OpenTK.Platform.Windows.WinGLNative.WndProc (System.Windows.Forms.Message&) <0x003fd>
at System.Windows.Forms.NativeWindow.WndProc (intptr,System.Windows.Forms.Msg,intptr,intptr) <0x0015c>
at System.Windows.Forms.XplatUIWin32.InternalWndProc (intptr,System.Windows.Forms.Msg,intptr,intptr) <0x00046>
at (wrapper native-to-managed) System.Windows.Forms.XplatUIWin32.InternalWndProc (intptr,System.Windows.Forms.Msg,intptr,intptr) <0x00065>
at (wrapper managed-to-native) System.Windows.Forms.XplatUIWin32.Win32CreateWindow (System.Windows.Forms.WindowExStyles,string,string,System.Windows.Forms.WindowStyles,int,int,int,int,intptr,intptr,intptr,intptr) <0x00004>
at System.Windows.Forms.XplatUIWin32.CreateWindow (System.Windows.Forms.CreateParams) <0x0039f>
at System.Windows.Forms.XplatUI.CreateWindow (System.Windows.Forms.CreateParams) <0x00015>
at System.Windows.Forms.NativeWindow.CreateHandle (System.Windows.Forms.CreateParams) <0x00037>
at OpenTK.Platform.Windows.WinGLNative.CreateWindow (int,int,OpenTK.Graphics.GraphicsMode,OpenTK.Graphics.IGraphicsContext&) <0x00109>
at OpenTK.GameWindow..ctor (int,int,OpenTK.Graphics.GraphicsMode,string,OpenTK.GameWindowFlags,OpenTK.Graphics.DisplayDevice) <0x00175>
This is happening on Mono v1.9.1.
You can reproduce this error simply by running Examples.exe which comes with OpenTK on Mono and select GLSL 1: First shader Example.
Do I need to do some special actions to get .net executable working on Mono? I understand that any .net executable even if it is compiled with Microsoft.NET C# compiler can be run on Mono without recompiling, right?




Comments
Jun 29
15:09:00Re: Exception in OpenTK.Platform.Windows.WMInput..ctor on Mono
posted by the FiddlerLooks like you are the first one to run OpenTK on Mono/Windows :)
I've never tested this configuration and I'm not really surprised it doesn't work. Windows is somewhat of a second-class citizen to Mono, and with good cause (politics and software freedom aside).
Judging from the stacktrace, this looks like a bug in the Mono WinForms implementation (AssignHandle fails internally). Can you please run Examples.exe using the debug OpenTK.dll? Its output will help pinpoint the exact location of the error, se we can file a bug to the Mono team.
With a little luck, it will be possible to get OpenTK to run on Mono 2.0 (which should arrive around September). I don't plan to spend too much time on this, but it would be nice as a sign of maturity for the Mono platform and OpenTK.
Jun 29
18:24:00Re: Exception in WMInput..ctor on Mono
posted by martinsmAs I understand Mono 1.9.1 actually counts as 2.0 beta version. See here - "Latest Version: 1.9.1 (Mono 2.0 Beta)".
I also don't use mono for .net applications on Windows. MS.NET is fine for me. I just wanted to verify if everything works also for Mono before trying my applications with OpenTK on different OS (Linux/MacOSX).
Here is console output from debug build of Examples+OpenTK:
DisplayDevice 0 (primary) supports 794 resolutions.
320x200x8@60Hz
... lots of display resolutions ...
800x600x4@1Hz
Creating default GraphicsMode (32, 16, 0, 0, 0, 2, False).
Device context: -1056889723
Selecting pixel format... Native window driver: OpenTK.Platform.Windows.WinGLNative
Creating native window.
Initalizing WMInput driver.
System.ArgumentException: Key duplication when adding: 1379194
at System.Collections.Hashtable.PutImpl (object,object,bool) <0x001ac>
at System.Collections.Hashtable.Add (object,object) <0x00012>
at System.Windows.Forms.NativeWindow.AssignHandle (intptr) <0x00074>
at OpenTK.Platform.Windows.WMInput..ctor (OpenTK.Platform.Windows.WinWindowInfo) <0x00185>
at (wrapper remoting-invoke-with-check) OpenTK.Platform.Windows.WMInput..ctor (OpenTK.Platform.Windows.WinWindowInfo) <0x00029>
at OpenTK.Platform.Windows.WinGLNative.OnCreate (System.EventArgs) <0x0008f>
at OpenTK.Platform.Windows.WinGLNative.WndProc (System.Windows.Forms.Message&) <0x00443>
at System.Windows.Forms.NativeWindow.WndProc (intptr,System.Windows.Forms.Msg,intptr,intptr) <0x0015c>
at System.Windows.Forms.XplatUIWin32.InternalWndProc (intptr,System.Windows.Forms.Msg,intptr,intptr) <0x00046>
at (wrapper native-to-managed) System.Windows.Forms.XplatUIWin32.InternalWndProc (intptr,System.Windows.Forms.Msg,intptr,intptr) <0x00065>
at (wrapper managed-to-native) System.Windows.Forms.XplatUIWin32.Win32CreateWindow (System.Windows.Forms.WindowExStyles,string,string,System.Windows.Forms.WindowStyles,int,int,int,int,intptr,intptr,intptr,intptr) <0x00004>
at System.Windows.Forms.XplatUIWin32.CreateWindow (System.Windows.Forms.CreateParams) <0x0039f>
at System.Windows.Forms.XplatUI.CreateWindow (System.Windows.Forms.CreateParams) <0x00015>
at System.Windows.Forms.NativeWindow.CreateHandle (System.Windows.Forms.CreateParams) <0x00037>
at OpenTK.Platform.Windows.WinGLNative.CreateWindow (int,int,OpenTK.Graphics.GraphicsMode,OpenTK.Graphics.IGraphicsContext&) <0x0011d>
at OpenTK.GameWindow..ctor (int,int,OpenTK.Graphics.GraphicsMode,string,OpenTK.GameWindowFlags,OpenTK.Graphics.DisplayDevice) <0x00204>
Destroying window: Windows.WindowInfo: Handle 1379194, Parent (null)
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Key duplication when adding: 1379194
at System.Collections.Hashtable.PutImpl (object,object,bool) <0x001ac>
at System.Collections.Hashtable.Add (object,object) <0x00012>
at System.Windows.Forms.NativeWindow.AssignHandle (intptr) <0x00074>
at OpenTK.Platform.Windows.WMInput..ctor (OpenTK.Platform.Windows.WinWindowInfo) <0x00185>
at (wrapper remoting-invoke-with-check) OpenTK.Platform.Windows.WMInput..ctor (OpenTK.Platform.Windows.WinWindowInfo) <0x00029>
at OpenTK.Platform.Windows.WinGLNative.OnCreate (System.EventArgs) <0x0008f>
at OpenTK.Platform.Windows.WinGLNative.WndProc (System.Windows.Forms.Message&) <0x00443>
at System.Windows.Forms.NativeWindow.WndProc (intptr,System.Windows.Forms.Msg,intptr,intptr) <0x0015c>
at System.Windows.Forms.XplatUIWin32.InternalWndProc (intptr,System.Windows.Forms.Msg,intptr,intptr) <0x00046>
at (wrapper native-to-managed) System.Windows.Forms.XplatUIWin32.InternalWndProc (intptr,System.Windows.Forms.Msg,intptr,intptr) <0x00065>
at (wrapper managed-to-native) System.Windows.Forms.XplatUIWin32.Win32CreateWindow (System.Windows.Forms.WindowExStyles,string,string,System.Windows.Forms.WindowStyles,int,int,int,int,intptr,intptr,intptr,intptr) <0x00004>
at System.Windows.Forms.XplatUIWin32.CreateWindow (System.Windows.Forms.CreateParams) <0x0039f>
at System.Windows.Forms.XplatUI.CreateWindow (System.Windows.Forms.CreateParams) <0x00015>
at System.Windows.Forms.NativeWindow.CreateHandle (System.Windows.Forms.CreateParams) <0x00037>
at OpenTK.Platform.Windows.WinGLNative.CreateWindow (int,int,OpenTK.Graphics.GraphicsMode,OpenTK.Graphics.IGraphicsContext&) <0x0011d>
at OpenTK.GameWindow..ctor (int,int,OpenTK.Graphics.GraphicsMode,string,OpenTK.GameWindowFlags,OpenTK.Graphics.DisplayDevice) <0x00204>
--- End of inner exception stack trace ---
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000]
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000]
at Examples.ExampleLauncher.RunExample () [0x00000]
Jun 29
21:03:38Re: Exception in WMInput..ctor on Mono
posted by the FiddlerThanks, this confirms the exact position of the error: the call to AssignHandle fails. I'll ping the WinForm mailing list on the issue.
A little background info:
OpenTK uses a technique known as "subclassing" which can be used to intercept WM_* messages before they reach their target window. The
System.Windows.Forms.AssignHandlemethod does exactly that and is quite useful, as it allows the input drivers to any valid window. This allows to "hook" a MouseDevice to any Windows.Forms.Control, for example.Why do that? Because OpenTK can detect and use multiple mice/keyboards, which isn't possible with plain old Windows.Forms.
In any case, this problem affects a Windows-specific part of OpenTK/Mono. Linux/MacOS use completely different code and don't suffer from this issue.