From 516bcca8f387921815a612f432262787380d7b0c Mon Sep 17 00:00:00 2001 From: Fraser Waters Date: Tue, 21 Oct 2014 20:25:37 +0200 Subject: [PATCH] Throw exception if ProcessEvents isn't called on main thread. --- Source/OpenTK/NativeWindow.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Source/OpenTK/NativeWindow.cs b/Source/OpenTK/NativeWindow.cs index 6e892db9..d4a4cf1b 100644 --- a/Source/OpenTK/NativeWindow.cs +++ b/Source/OpenTK/NativeWindow.cs @@ -54,6 +54,10 @@ namespace OpenTK private bool cursor_visible = true; private bool previous_cursor_visible = true; + /// + /// System.Threading.Thread.CurrentThread.ManagedThreadId of the thread that created this . + /// + 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(); }