Raylib_cs terminates after loading font to static member

I’m trying to load a font into an object that is a member of a static class in the C# binding of Raylib. My objective is to use a single static class accessible from across my entire project using a single namespace. I use Newtonsoft’s JSON library to de-serialize my objects. Since I’ve had trouble de-serializing into a static class in a neat and compact way, I’ve resorted into a solution like this:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>using Raylib_cs;
using Newtonsoft.Json;
using System.Runtime.Serialization;
namespace Game.Configs
{
public static class Configuration
{
/*Debug config*/
private static DebugConfig? _debug;
public static DebugConfig Debug => _debug!;
/*Graphics config*/
private static GraphicsConfig? _graphics;
public static GraphicsConfig Graphics => _graphics!;
public static void Load(string Path)
{
try
{
_debug = JsonConvert.DeserializeObject<DebugConfig>(File.ReadAllText($"{Path}dbg.json"))!;
_graphics = JsonConvert.DeserializeObject<GraphicsConfig>(File.ReadAllText($"{Path}gfx.json"))!;
}
catch (Exception e)
{
// Log the exception
Console.WriteLine($"Exception during deserialization: {e}");
}
}
}
//these classes are in separate source files, but within the same namespace so I added them here
public class DebugConfig
{
public string? FontPath {get; set;}
[JsonIgnore]
public Font DebugFont {get;set;}
[OnDeserialized]
internal void OnDeserializedMethod(StreamingContext context)
{
if(!string.IsNullOrEmpty(FontPath))
DebugFont = Raylib.LoadFont(FontPath);
}
}
public class GraphicsConfig
{
public string? Title {get; set;}
public V2Di Resolution {get;set;}
public bool Windowed {get;set;}
public byte Framerate {get;set;}
}
}
</code>
<code>using Raylib_cs; using Newtonsoft.Json; using System.Runtime.Serialization; namespace Game.Configs { public static class Configuration { /*Debug config*/ private static DebugConfig? _debug; public static DebugConfig Debug => _debug!; /*Graphics config*/ private static GraphicsConfig? _graphics; public static GraphicsConfig Graphics => _graphics!; public static void Load(string Path) { try { _debug = JsonConvert.DeserializeObject<DebugConfig>(File.ReadAllText($"{Path}dbg.json"))!; _graphics = JsonConvert.DeserializeObject<GraphicsConfig>(File.ReadAllText($"{Path}gfx.json"))!; } catch (Exception e) { // Log the exception Console.WriteLine($"Exception during deserialization: {e}"); } } } //these classes are in separate source files, but within the same namespace so I added them here public class DebugConfig { public string? FontPath {get; set;} [JsonIgnore] public Font DebugFont {get;set;} [OnDeserialized] internal void OnDeserializedMethod(StreamingContext context) { if(!string.IsNullOrEmpty(FontPath)) DebugFont = Raylib.LoadFont(FontPath); } } public class GraphicsConfig { public string? Title {get; set;} public V2Di Resolution {get;set;} public bool Windowed {get;set;} public byte Framerate {get;set;} } } </code>
using Raylib_cs;
using Newtonsoft.Json;
using System.Runtime.Serialization;
namespace Game.Configs
{
    public static class Configuration
    {
        /*Debug config*/
        private static DebugConfig? _debug;
        public static DebugConfig Debug => _debug!;

        /*Graphics config*/
        private static GraphicsConfig? _graphics;
        public static GraphicsConfig Graphics => _graphics!;
        

        public static void Load(string Path)
        {
            try
            {
                _debug = JsonConvert.DeserializeObject<DebugConfig>(File.ReadAllText($"{Path}dbg.json"))!;
                _graphics = JsonConvert.DeserializeObject<GraphicsConfig>(File.ReadAllText($"{Path}gfx.json"))!;
            }
            catch (Exception e)
            {
                // Log the exception
                Console.WriteLine($"Exception during deserialization: {e}");
            }

        }
    }
    //these classes are in separate source files, but within the same namespace so I added them here
    public class DebugConfig
    {
        public string? FontPath {get; set;}
        [JsonIgnore]
        public Font DebugFont {get;set;}
        [OnDeserialized]
        internal void OnDeserializedMethod(StreamingContext context)
        {
            if(!string.IsNullOrEmpty(FontPath))
                DebugFont = Raylib.LoadFont(FontPath);
        }
    }
    public class GraphicsConfig
    {
        public  string? Title {get; set;}
        public  V2Di Resolution {get;set;}
        public  bool Windowed {get;set;}
        public  byte Framerate {get;set;}
    }
}

And I have a “Game” class which is implemented like so:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>partial class Game
{
public Game()
{
Configuration.Load("res/cfg/");
}
public void Initialize()
{
Raylib.InitWindow(Configuration.Graphics.Resolution.X,Configuration.Graphics.Resolution.Y,Configuration.Graphics.Title);
if(!Configuration.Graphics.Windowed && !Raylib.IsWindowFullscreen())
Raylib.ToggleFullscreen();
Raylib.SetTargetFPS(Configuration.Graphics.Framerate);
Start();
}
}
</code>
<code>partial class Game { public Game() { Configuration.Load("res/cfg/"); } public void Initialize() { Raylib.InitWindow(Configuration.Graphics.Resolution.X,Configuration.Graphics.Resolution.Y,Configuration.Graphics.Title); if(!Configuration.Graphics.Windowed && !Raylib.IsWindowFullscreen()) Raylib.ToggleFullscreen(); Raylib.SetTargetFPS(Configuration.Graphics.Framerate); Start(); } } </code>
partial class Game
{
    public Game()
    {
        Configuration.Load("res/cfg/");
    }
    public void Initialize()
    {
        Raylib.InitWindow(Configuration.Graphics.Resolution.X,Configuration.Graphics.Resolution.Y,Configuration.Graphics.Title);
        if(!Configuration.Graphics.Windowed && !Raylib.IsWindowFullscreen())
            Raylib.ToggleFullscreen();
        Raylib.SetTargetFPS(Configuration.Graphics.Framerate);
        Start();
    }
}

The Game constructor is called first thing in my program entry point. Running in debug, the program immediately terminates itself after raylib reporting a successful load of Configuration.Debug.DebugFont from said object’s de-serialization callback method.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>INFO: FILEIO: [res/fnt/_stmr.ttf] File loaded successfully
The program '[24301] rayNet' has exited with code 0 (0x0).
</code>
<code>INFO: FILEIO: [res/fnt/_stmr.ttf] File loaded successfully The program '[24301] rayNet' has exited with code 0 (0x0). </code>
INFO: FILEIO: [res/fnt/_stmr.ttf] File loaded successfully
The program '[24301] rayNet' has exited with code 0 (0x0).

Loading the font into it’s own static variable within the “Game” class works just fine: public static Font ttfTest = Raylib.LoadFont("res/fnt/_stmr.ttf");
And the loading and use of Configuration.Graphics works as expected. Commenting out the line:
_debug = JsonConvert.DeserializeObject<DebugConfig>(File.ReadAllText($"{Path}dbg.json"))!; in the Configuration class prevents the application from terminating on load, and the de-serialized data for Configuration.Graphics works just fine.
There are no exceptions thrown on program termination, or any warnings when compiling. What causes Configuration.Graphics to work, but not
Configuration.Debug?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật