From 441d602a6d74a950bf906f0655c087969b24c0a1 Mon Sep 17 00:00:00 2001 From: Pavlos Touboulidis Date: Thu, 15 May 2014 02:23:03 +0300 Subject: [PATCH] Fix thread synchronization problem with Sheet.dirty --- OpenRA.Game/Graphics/Sheet.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/OpenRA.Game/Graphics/Sheet.cs b/OpenRA.Game/Graphics/Sheet.cs index 4e8cef072c..47e7eb2ff6 100644 --- a/OpenRA.Game/Graphics/Sheet.cs +++ b/OpenRA.Game/Graphics/Sheet.cs @@ -21,6 +21,7 @@ namespace OpenRA.Graphics ITexture texture; bool dirty; byte[] data; + readonly object dirtyLock = new object(); public readonly Size Size; public byte[] Data { get { return data ?? texture.GetData(); } } @@ -68,6 +69,8 @@ namespace OpenRA.Graphics public ITexture Texture { + // This is only called from the main thread but 'dirty' + // is set from other threads too via CommitData(). get { if (texture == null) @@ -78,8 +81,11 @@ namespace OpenRA.Graphics if (dirty) { - texture.SetData(data, Size.Width, Size.Height); - dirty = false; + lock (dirtyLock) + { + texture.SetData(data, Size.Width, Size.Height); + dirty = false; + } } return texture; @@ -140,7 +146,10 @@ namespace OpenRA.Graphics if (data == null) throw new InvalidOperationException("Texture-wrappers are read-only"); - dirty = true; + lock (dirtyLock) + { + dirty = true; + } } } }