From 0d275a4df3b6bbcb990a9715d0f037789624c377 Mon Sep 17 00:00:00 2001 From: The0x539 Date: Tue, 27 Jan 2026 08:26:39 -0600 Subject: [PATCH] Avoid accidentally (indirectly) reading PlatformHelper.Current before setting it (#1254) --- BepInEx.Preloader.Core/PlatformUtils.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/BepInEx.Preloader.Core/PlatformUtils.cs b/BepInEx.Preloader.Core/PlatformUtils.cs index a0d33c2..917a7a8 100644 --- a/BepInEx.Preloader.Core/PlatformUtils.cs +++ b/BepInEx.Preloader.Core/PlatformUtils.cs @@ -80,7 +80,12 @@ internal static class PlatformUtils if (wineGetVersion != IntPtr.Zero) { current |= Platform.Wine; - var getVersion = wineGetVersion.AsDelegate(); + // It's not safe to use the AsDelegate() extension method here because: + // - It comes from the MonoMod.Utils.DynDll class, defined in MonoMod.Common. + // - The DynDll class has a static constructor that reads PlatformHelper.Current. + // - Reading from that property freezes it: subsequent writes will throw an exception. + // - This method only sets PlatformHelper.Current at the very end. + var getVersion = Marshal.GetDelegateForFunctionPointer(wineGetVersion, typeof(GetWineVersionDelegate)) as GetWineVersionDelegate; WineVersion = getVersion(); } }