Throw exception if ProcessEvents isn't called on main thread.

This commit is contained in:
Fraser Waters 2014-10-21 20:25:37 +02:00
parent f8af961d54
commit 516bcca8f3

View file

@ -54,6 +54,10 @@ namespace OpenTK
private bool cursor_visible = true; private bool cursor_visible = true;
private bool previous_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 #endregion
#region --- Contructors --- #region --- Contructors ---
@ -102,6 +106,8 @@ namespace OpenTK
this.options = options; this.options = options;
this.device = device; this.device = device;
this.thread_id = System.Threading.Thread.CurrentThread.ManagedThreadId;
IPlatformFactory factory = Factory.Default; IPlatformFactory factory = Factory.Default;
implementation = factory.CreateNativeWindow(x, y, width, height, title, mode, options, this.device); implementation = factory.CreateNativeWindow(x, y, width, height, title, mode, options, this.device);
factory.RegisterResource(this); factory.RegisterResource(this);
@ -1049,6 +1055,10 @@ namespace OpenTK
protected void ProcessEvents(bool retainEvents) protected void ProcessEvents(bool retainEvents)
{ {
EnsureUndisposed(); 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; if (!retainEvents && !events) Events = true;
implementation.ProcessEvents(); implementation.ProcessEvents();
} }