stride3d/stride · error · InvalidOperationException

The font system is not initialized yet

Error message

The font system is not initialized yet

What it means

Game.Font throws InvalidOperationException when the underlying GameFontSystem has not yet created its FontSystem. The font factory is only available after the font system is initialized during the game's setup, so early access fails. It signals an access-order bug rather than a bad input.

Solutions

  1. Move the code that reads Game.Font to after the game is initialized (e.g. first Script update, Start/Initialize phase).
  2. Guard the access by checking that the font system is ready before using the Font property.
  3. If the font system should be ready, check your Game initialization flags/order so font setup is not skipped.

Example fix

// before
public MyGame()
{
    var factory = Font; // throws before init
}
// after
public override void Update(GameTime time)
{
    var factory = Font; // safe after initialization
}
Defensive patterns

Strategy: validation

Validate before calling

if (game.Font == null || game.GameFontSystem?.FontSystem == null) { /* defer until after Init */ }

Type guard

bool CanUseFont(Game g) => g?.GameFontSystem?.FontSystem != null;

Prevention

When it happens

Trigger: Accessing the public Game.Font property before GameBase.Initialize/Run has set up gameFontSystem.FontSystem (i.e. GameFontSystem.FontSystem == null).

Common situations: Reading Game.Font in the Game constructor or in scene/entity initialization that runs before the game loop starts; loading fonts during content script preload before initialization completed.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/4ac5ad350783c3dd. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Engine/Engine/Game.cs:131

        /// </summary>
        public GameProfilingSystem ProfilingSystem { get; }

        /// <summary>
        /// Gets the VR Device System.
        /// </summary>
        public VRDeviceSystem VRDeviceSystem { get; }

        /// <summary>
        /// Gets the font system.
        /// </summary>
        /// <value>The font system.</value>
        /// <exception cref="System.InvalidOperationException">The font system is not initialized yet</exception>
        public IFontFactory Font
        {
            get
            {
                if (gameFontSystem.FontSystem == null)
                    throw new InvalidOperationException("The font system is not initialized yet");

                return gameFontSystem.FontSystem;
            }
        }

        /// <summary>
        /// Gets or sets the console log mode. See remarks.
        /// </summary>
        /// <value>The console log mode.</value>
        /// <remarks>
        /// Defines how the console will be displayed when running the game. By default, on Windows, It will open only on debug
        /// if there are any messages logged.
        /// </remarks>
        public ConsoleLogMode ConsoleLogMode
        {
            get
            {
                var consoleLogListener = logListener as ConsoleLogListener;

View on GitHub (pinned to 96fad776d2)