Fix potential exception that I was ignoring.
authorPaul Kratt <sappharad@Mercury.local>
Sat, 22 Feb 2014 03:36:22 +0000 (21:36 -0600)
committerPaul Kratt <sappharad@Mercury.local>
Wed, 26 Feb 2014 00:46:07 +0000 (18:46 -0600)
This can happen, so we should handle it

Source/GLControl/CarbonGLControl.cs

index 380a735..58589f9 100644 (file)
@@ -54,10 +54,13 @@ namespace OpenTK
                }
 
                private int GetYOffset(){
-                       System.Drawing.Point offset = control.PointToScreen(control.Location);
-                       System.Drawing.Point windowOffset = control.TopLevelControl.PointToScreen(System.Drawing.Point.Empty);
-                       int relativeY = offset.Y-windowOffset.Y; //control.TopLevelControl.Location.Y is not the same as windowOffset.Y for some reason.
-                       return control.TopLevelControl.ClientSize.Height - control.Bottom - relativeY;
+                       if (control.TopLevelControl != null) {
+                               System.Drawing.Point offset = control.PointToScreen (control.Location);
+                               System.Drawing.Point windowOffset = control.TopLevelControl.PointToScreen (System.Drawing.Point.Empty);
+                               int relativeY = offset.Y - windowOffset.Y; //control.TopLevelControl.Location.Y is not the same as windowOffset.Y for some reason.
+                               return control.TopLevelControl.ClientSize.Height - control.Bottom - relativeY;
+                       }
+                       return control.Location.Y;
                }
 
         #region IGLControl Members