Fixed race condition in GraphicsMode.Default.
This commit is contained in:
parent
baf44cff90
commit
9b63078b11
1 changed files with 14 additions and 11 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue