Throw exception if ProcessEvents isn't called on main thread.
authorFraser Waters <frassle@gmail.com>
Tue, 21 Oct 2014 18:25:37 +0000 (20:25 +0200)
committerFraser Waters <frassle@gmail.com>
Mon, 3 Nov 2014 22:41:19 +0000 (23:41 +0100)
Source/OpenTK/NativeWindow.cs

index 6e892db..d4a4cf1 100644 (file)
@@ -54,6 +54,10 @@ namespace OpenTK
         private bool cursor_visible = true;
         private bool previous_cursor_visible = true;
 
+        /// <summary>
+        /// System.Threading.Thread.CurrentThread.ManagedThreadId of the thread that created this <see cref="OpenTK.NativeWindow"/>.
+        /// </summary>
+        private int thread_id;
         #endregion
 
         #region --- Contructors ---
@@ -102,6 +106,8 @@ namespace OpenTK
             this.options = options;
             this.device = device;
 
+            this.thread_id = System.Threading.Thread.CurrentThread.ManagedThreadId;
+
             IPlatformFactory factory = Factory.Default;
             implementation = factory.CreateNativeWindow(x, y, width, height, title, mode, options, this.device);
             factory.RegisterResource(this);
@@ -1049,6 +1055,10 @@ namespace OpenTK
         protected void ProcessEvents(bool retainEvents)
         {
             EnsureUndisposed();
+            if (this.thread_id != System.Threading.Thread.CurrentThread.ManagedThreadId)
+            {
+                throw new InvalidOperationException("ProcessEvents must be called on the same thread that created the window.");
+            }
             if (!retainEvents && !events) Events = true;
             implementation.ProcessEvents();
         }