iliak's picture

1.0 beta-1 throws TypeInitializationException in OpenTK.Platform.X11.API when running on windows

Project:The Open Toolkit library
Category:bug report

Don't know if it's really a bug or not, but here's the problem.

With the 0.9x svn version of the dll (before testing 1.x beta) no real problems detected. The beta 1 allowed me to detect a problem (GL.Begin()... GL.Begin()... GL.End() ... GL.End()). With the Debug version, it throws an error "InvalidOperation" :

   à OpenTK.Graphics.OpenGL.ErrorHelper.CheckErrors()
   à OpenTK.Graphics.OpenGL.ErrorHelper.Dispose()
   à OpenTK.Graphics.OpenGL.GL.End()
   à ArcEngine.Graphic.Display.DrawPoint(Int32 x, Int32 y, Color color) dans D:\Dev\ArcEngine\Framework\Graphic\Display.cs:ligne 677
   à ArcEngine.Graphic.Display.DrawPoint(Point point, Color color) dans D:\Dev\ArcEngine\Framework\Graphic\Display.cs:ligne 660
   à ArcEngine.Graphic.Shape.BezierCurveTo(Point point, Point control1, Point control2) dans D:\Dev\ArcEngine\Framework\Graphic\Shape.cs:ligne 162
   à PathDemo.EmptyProject.Draw() dans D:\Dev\ArcEngine\Examples\Path Demo\Program.cs:ligne 180
   à ArcEngine.Game.Tick() dans D:\Dev\ArcEngine\Framework\Game.cs:ligne 272
   à ArcEngine.Game.Application_Idle(Object sender, EventArgs e) dans D:\Dev\ArcEngine\Framework\Game.cs:ligne 401
   à System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
   à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   à System.Windows.Forms.Application.Run(Form mainForm)
   à ArcEngine.Game.Run() dans D:\Dev\ArcEngine\Framework\Game.cs:ligne 347
   à PathDemo.EmptyProject.Main() dans D:\Dev\ArcEngine\Examples\Path Demo\Program.cs:ligne 54

I remove the portion of bugged code, no problems.

With the Release version, no error about mixed GL.Begin() / GL.End() calls, but an error when exiting the app :

// French mode :)
L'exception System.TypeInitializationException n'a pas été gérée
Message: Une exception a été levée par l'initialiseur de type pour 'OpenTK.Platform.X11.API'.

This error raises even if I remove the boggus code.

You can have a look at my code (rev 316).

I don't know if it's an error, but it's a different behaviour of the dll.


Comment viewing options

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


Title:Strange behaviour between 0.9x and 1.0beta» 1.0 beta-1 throws TypeInitializationException in OpenTK.Platform.X11.API when running on windows
Status:open» confirmed

There are two independent issues at work here.

First, the InvalidOperation error thrown in the Debug version: both OpenTK 0.9.x and 1.0 checks for errors automatically every time you call an OpenGL function - but only in the debug version of the dll (the behavior is the same on both 0.9.x and 1.0). These checks are disabled in the release version of OpenTK.dll, because they carry a large performance penalty. My suggestion is to develop using the debug version and only switch to release when testing performance or doing an actual release.

Ideally, you'd be able to enable this error checking at runtime using a single OpenTK.dll (instead of changing between debug and release). Unfortunately, I haven't been able to find a way to do this without impacting runtime performance, so this remains wishlist item for a future release.

The TypeInitializationException is a (harmless) bug that crept in the 1.0 beta-1 release. I will fix it in beta-2.

iliak's picture


Any way to get ride of this borring window where I need to click on "Ok|Continue" ?

the Fiddler's picture


Status:confirmed» in progress (review)

Try upgrading to r2507 of the 1.0 branch. If this doesn't help, please post a stacktrace for the TypeInitializationException.

iliak's picture


Seems good now... What was the problem ?

the Fiddler's picture


Version:1.0-beta-1» 0.9.x-dev
Status:in progress (review)» fixed

Thanks for testing!

The platform detection code tries to initialize each platform in order and marks a platform as unsupported if this initialization fails. The issue was that the X11 platform would register a cleanup handler even if initialization failed, causing some X11-specific code to run even on shutdown.

the Fiddler's picture


Version:0.9.x-dev» 1.0-beta-2
Status:fixed» closed

Closing issues fixed in 1.0 beta-2.