{
class Sdl2Factory : PlatformFactoryBase
{
- readonly Sdl2InputDriver InputDriver = new Sdl2InputDriver();
+ private readonly object inputDriverLock = new object();
+ private Sdl2InputDriver inputDriver;
/// <summary>
/// Gets or sets a value indicating whether to use SDL2 fullscreen-desktop mode
public override IKeyboardDriver2 CreateKeyboardDriver()
{
- return InputDriver.KeyboardDriver;
+ return GetInputDriver().KeyboardDriver;
}
public override IMouseDriver2 CreateMouseDriver()
{
- return InputDriver.MouseDriver;
+ return GetInputDriver().MouseDriver;
}
public override IJoystickDriver2 CreateJoystickDriver()
{
- return InputDriver.JoystickDriver;
+ return GetInputDriver().JoystickDriver;
}
#endregion
{
if (manual)
{
- InputDriver.Dispose();
+ if (inputDriver != null)
+ {
+ inputDriver.Dispose();
+ inputDriver = null;
+ }
}
base.Dispose(manual);
}
#endregion
+
+ private Sdl2InputDriver GetInputDriver()
+ {
+ if (inputDriver == null)
+ {
+ lock (inputDriverLock)
+ {
+ // Check again inside the lock
+ if (inputDriver == null)
+ inputDriver = new Sdl2InputDriver();
+ }
+ }
+
+ return inputDriver;
+ }
}
}