Skip to content

Commit dbf70a3

Browse files
authored
Merge pull request #2446 from disarray2077/fix_static_order
Fix static initialization order issue in AllowFail classes
2 parents e5834e7 + 95d6475 commit dbf70a3

3 files changed

Lines changed: 17 additions & 18 deletions

File tree

BeefLibs/Beefy2D/src/gfx/Font.bf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,14 @@ namespace Beefy.gfx
263263
#if BF_PLATFORM_LINUX
264264

265265
const String FONTCONFIG_LIB = "libfontconfig.so";
266-
static bool IsFontconfigAvailable { get; private set; } = true;
266+
static bool IsFontconfigAvailable { get; private set; }
267267

268268
[AlwaysInclude, StaticInitPriority(100)]
269269
private static class FontconfigAllowFail
270270
{
271271
static this()
272272
{
273+
SelfOuter.IsFontconfigAvailable = true;
273274
Runtime.AddErrorHandler(new (stage, error) => {
274275
if (stage == .PreFail)
275276
{

BeefLibs/corlib/src/IO/FileDialog.bf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,9 @@ enum DialogResult
589589

590590
abstract class CommonDialog
591591
{
592-
protected Linux.DBus* mBus ~ Linux.SdBusUnref(_);
593-
protected Linux.DBusMsg* mRequest ~ Linux.SdBusMessageUnref(_);
594-
protected Linux.DBusErr mError ~ Linux.SdBusErrorFree(&_);
592+
protected Linux.DBus* mBus ~ if (_ != null) Linux.SdBusUnref(_);
593+
protected Linux.DBusMsg* mRequest ~ if (_ != null) Linux.SdBusMessageUnref(_);
594+
protected Linux.DBusErr mError ~ if (_ != default) Linux.SdBusErrorFree(&_);
595595
protected String mTitle ~ delete _;
596596
protected String mInitialDir ~ delete _;
597597
protected String[] mFileNames ~ DeleteContainerAndItems!(_);

BeefLibs/corlib/src/Linux.bf

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,28 @@ class Linux
4444

4545
public typealias DBusMsgHandler = function int32(DBusMsg *m, void *userdata, DBusErr *ret_error);
4646

47-
public static bool IsSystemdAvailable { get; private set; } = true;
47+
public static bool IsSystemdAvailable { get; private set; }
4848

4949
[AlwaysInclude, StaticInitPriority(100)]
5050
static class AllowFail
5151
{
5252
public static this()
5353
{
54-
Runtime.AddErrorHandler(new => Handle);
55-
}
56-
57-
public static Runtime.ErrorHandlerResult Handle(Runtime.ErrorStage errorStage, Runtime.Error error)
58-
{
59-
if (errorStage == .PreFail)
60-
{
61-
if (var loadLibaryError = error as Runtime.LoadSharedLibraryError)
54+
IsSystemdAvailable = true;
55+
Runtime.AddErrorHandler(new (stage, error) => {
56+
if (stage == .PreFail)
6257
{
63-
if (loadLibaryError.mPath == "libsystemd.so")
58+
if (var loadLibaryError = error as Runtime.LoadSharedLibraryError)
6459
{
65-
IsSystemdAvailable = false;
66-
return .Ignore;
60+
if (loadLibaryError.mPath == "libsystemd.so")
61+
{
62+
IsSystemdAvailable = false;
63+
return .Ignore;
64+
}
6765
}
6866
}
69-
}
70-
return .ContinueFailure;
67+
return .ContinueFailure;
68+
});
7169
}
7270
}
7371

0 commit comments

Comments
 (0)