From ac404e35fbd47dcb22b9e61a77a79e07a7ab7d25 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Mon, 19 Oct 2009 17:38:16 +0000 Subject: [PATCH] * GLControlFactory.cs: More defensive checks for null GraphicsModes. * GLControl.cs: More defensive checks for null GraphicsModes. Set flags, context version and GraphicsMode before calling InitializeComponents(), as the latter might cause the context to be created (and we need this information before creating the context). Fixes ArgumentNullException on Linux. --- Source/GLControl/GLControl.cs | 7 +++++-- Source/GLControl/GLControlFactory.cs | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Source/GLControl/GLControl.cs b/Source/GLControl/GLControl.cs index 340b82f9..e69225cc 100644 --- a/Source/GLControl/GLControl.cs +++ b/Source/GLControl/GLControl.cs @@ -78,17 +78,20 @@ namespace OpenTK /// The GraphicsContextFlags for the OpenGL GraphicsContext. public GLControl(GraphicsMode mode, int major, int minor, GraphicsContextFlags flags) { + if (mode == null) + throw new ArgumentNullException("mode"); + SetStyle(ControlStyles.Opaque, true); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); DoubleBuffered = false; - InitializeComponent(); - this.format = mode; this.major = major; this.minor = minor; this.flags = flags; + + InitializeComponent(); } #endregion diff --git a/Source/GLControl/GLControlFactory.cs b/Source/GLControl/GLControlFactory.cs index d854d7ae..4040fe99 100644 --- a/Source/GLControl/GLControlFactory.cs +++ b/Source/GLControl/GLControlFactory.cs @@ -38,6 +38,11 @@ namespace OpenTK { public IGLControl CreateGLControl(GraphicsMode mode, Control control) { + if (mode == null) + throw new ArgumentNullException("mode"); + if (control == null) + throw new ArgumentNullException("control"); + if (Configuration.RunningOnWindows) return new WinGLControl(mode, control); else if (Configuration.RunningOnX11) return new X11GLControl(mode, control); else if (Configuration.RunningOnMacOS) return new CarbonGLControl(mode, control);