Added thread-affinity checks to SDL2 renderer.
If a call is made into a graphics resource that has thread-affinity, from a thread other than the one that created the graphics device, an exception will now be thrown to make debugging easier.
This commit is contained in:
31
OpenRA.Platforms.Default/ThreadAffine.cs
Normal file
31
OpenRA.Platforms.Default/ThreadAffine.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace OpenRA.Platforms.Default
|
||||
{
|
||||
abstract class ThreadAffine
|
||||
{
|
||||
readonly int managedThreadId;
|
||||
|
||||
protected ThreadAffine()
|
||||
{
|
||||
managedThreadId = Thread.CurrentThread.ManagedThreadId;
|
||||
}
|
||||
|
||||
protected void VerifyThreadAffinity()
|
||||
{
|
||||
if (managedThreadId != Thread.CurrentThread.ManagedThreadId)
|
||||
throw new InvalidOperationException("Cross-thread operation not valid: This method must be called from the same thread that created this object.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user