From f8083037f913a8d02096f7972e564817f4b2ef93 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Sat, 4 Jun 2022 13:16:20 -0700 Subject: [PATCH] Fixed static init ordering issue with DbgRawAllocData.Unmarked --- BeefLibs/corlib/src/Internal.bf | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/BeefLibs/corlib/src/Internal.bf b/BeefLibs/corlib/src/Internal.bf index 3bfe37cb..26b1f49a 100644 --- a/BeefLibs/corlib/src/Internal.bf +++ b/BeefLibs/corlib/src/Internal.bf @@ -11,12 +11,19 @@ namespace System public struct Unmarked { - public static DbgRawAllocData sRawAllocData; - public static this() + static DbgRawAllocData sRawAllocData; + public static DbgRawAllocData* Data { - sRawAllocData.mMarkFunc = null; - sRawAllocData.mMaxStackTrace = 1; - sRawAllocData.mType = typeof(T); + get + { + if (sRawAllocData.mMaxStackTrace == 0) + { + sRawAllocData.mMarkFunc = null; + sRawAllocData.mMaxStackTrace = 1; + sRawAllocData.mType = typeof(T); + } + return &sRawAllocData; + } } } } @@ -188,7 +195,7 @@ namespace System return new T[size]*(?); // We don't want to use the default mark function because the GC will mark the entire array, // whereas we have a custom marking routine because we only want to mark up to mSize - return (T*)Internal.Dbg_RawAlloc(size * strideof(T), &DbgRawAllocData.Unmarked.sRawAllocData); + return (T*)Internal.Dbg_RawAlloc(size * strideof(T), DbgRawAllocData.Unmarked.Data); #else return new T[size]*(?); #endif