Fix thread synchronization problem with Sheet.dirty
This commit is contained in:
@@ -21,6 +21,7 @@ namespace OpenRA.Graphics
|
|||||||
ITexture texture;
|
ITexture texture;
|
||||||
bool dirty;
|
bool dirty;
|
||||||
byte[] data;
|
byte[] data;
|
||||||
|
readonly object dirtyLock = new object();
|
||||||
|
|
||||||
public readonly Size Size;
|
public readonly Size Size;
|
||||||
public byte[] Data { get { return data ?? texture.GetData(); } }
|
public byte[] Data { get { return data ?? texture.GetData(); } }
|
||||||
@@ -68,6 +69,8 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
public ITexture Texture
|
public ITexture Texture
|
||||||
{
|
{
|
||||||
|
// This is only called from the main thread but 'dirty'
|
||||||
|
// is set from other threads too via CommitData().
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (texture == null)
|
if (texture == null)
|
||||||
@@ -78,8 +81,11 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
if (dirty)
|
if (dirty)
|
||||||
{
|
{
|
||||||
texture.SetData(data, Size.Width, Size.Height);
|
lock (dirtyLock)
|
||||||
dirty = false;
|
{
|
||||||
|
texture.SetData(data, Size.Width, Size.Height);
|
||||||
|
dirty = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return texture;
|
return texture;
|
||||||
@@ -140,7 +146,10 @@ namespace OpenRA.Graphics
|
|||||||
if (data == null)
|
if (data == null)
|
||||||
throw new InvalidOperationException("Texture-wrappers are read-only");
|
throw new InvalidOperationException("Texture-wrappers are read-only");
|
||||||
|
|
||||||
dirty = true;
|
lock (dirtyLock)
|
||||||
|
{
|
||||||
|
dirty = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user