From a8022ca3a1c9c2f312855c7676454507031be644 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Tue, 11 May 2021 19:57:21 -0300 Subject: [PATCH] Fix race in SM initialization (#2280) --- Ryujinx.HLE/HOS/Horizon.cs | 2 +- Ryujinx.HLE/HOS/Services/ServerBase.cs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Ryujinx.HLE/HOS/Horizon.cs b/Ryujinx.HLE/HOS/Horizon.cs index c240d1351..d8e1605ae 100644 --- a/Ryujinx.HLE/HOS/Horizon.cs +++ b/Ryujinx.HLE/HOS/Horizon.cs @@ -274,7 +274,7 @@ namespace Ryujinx.HLE.HOS public void InitializeServices() { IUserInterface sm = new IUserInterface(KernelContext); - sm.TrySetServer(new ServerBase(KernelContext, "SmServer") { SmObjectFactory = () => new IUserInterface(KernelContext) }); + sm.TrySetServer(new ServerBase(KernelContext, "SmServer", () => new IUserInterface(KernelContext))); // Wait until SM server thread is done with initialization, // only then doing connections to SM is safe. diff --git a/Ryujinx.HLE/HOS/Services/ServerBase.cs b/Ryujinx.HLE/HOS/Services/ServerBase.cs index 5b9834dcb..c9d009a9a 100644 --- a/Ryujinx.HLE/HOS/Services/ServerBase.cs +++ b/Ryujinx.HLE/HOS/Services/ServerBase.cs @@ -38,13 +38,14 @@ namespace Ryujinx.HLE.HOS.Services private readonly Dictionary> _ports = new Dictionary>(); public ManualResetEvent InitDone { get; } - public Func SmObjectFactory { get; set; } + public Func SmObjectFactory { get; } public string Name { get; } - public ServerBase(KernelContext context, string name) + public ServerBase(KernelContext context, string name, Func smObjectFactory = null) { InitDone = new ManualResetEvent(false); Name = name; + SmObjectFactory = smObjectFactory; _context = context; const ProcessCreationFlags flags =