Fixed race condition in GraphicsMode.Default.

This commit is contained in:
the_fiddler 2009-11-03 13:16:59 +00:00
parent baf44cff90
commit 9b63078b11

View file

@ -23,16 +23,19 @@ namespace OpenTK.Graphics
static GraphicsMode defaultMode;
static IGraphicsMode implementation;
static object mode_selection_lock = new object();
static readonly object SyncRoot = new object();
#region --- Constructors ---
#region static GraphicsMode()
static GraphicsMode()
{
lock (SyncRoot)
{
implementation = Platform.Factory.Default.CreateGraphicsMode();
}
}
#endregion
@ -180,10 +183,7 @@ namespace OpenTK.Graphics
if (index == null)
{
GraphicsMode mode;
lock (mode_selection_lock)
{
mode = implementation.SelectGraphicsMode(ColorFormat, Depth, Stencil, Samples, AccumulatorFormat, Buffers, Stereo);
}
Index = mode.Index;
ColorFormat = mode.ColorFormat;
@ -302,6 +302,8 @@ namespace OpenTK.Graphics
public static GraphicsMode Default
{
get
{
lock (SyncRoot)
{
if (defaultMode == null)
{
@ -312,6 +314,7 @@ namespace OpenTK.Graphics
return defaultMode;
}
}
}
#endregion