babalae/better-genshin-impact · error · Exception

截图器未初始化!

Error message

截图器未初始化!

What it means

A generic Exception thrown by the TaskTriggerDispatcher.GlobalGameCapture getter when the singleton exists but its GameCapture field is null. The dispatcher is initialized but the actual screenshot/capture backend was never assigned, so any capture-dependent operation must abort.

Source

Thrown at BetterGenshinImpact/GameTask/TaskTriggerDispatcher.cs:91

        public static TaskTriggerDispatcher Instance()
        {
            if (_instance == null)
            {
                throw new Exception("请先在启动页启动BetterGI,如果已经启动请重启");
            }

            return _instance;
        }

        public static IGameCapture GlobalGameCapture
        {
            get
            {
                _instance = Instance();

                if (_instance.GameCapture == null)
                {
                    throw new Exception("截图器未初始化!");
                }

                return _instance.GameCapture;
            }
        }

        public void ClearTriggers()
        {
            lock (_triggerListLocker)
            {
                GameTaskManager.ClearTriggers();
                _triggers?.Clear();
            }
        }

        public void SetTriggers(List<ITaskTrigger> list)
        {
            lock (_triggerListLocker)

View on GitHub (pinned to a7cb36712d)

Solutions

  1. On the startup page, start the screenshotter so GameCapture is assigned.
  2. Guard capture-consuming code with a null check on the dispatcher's GameCapture before use.
  3. If capture startup failed, restart BetterGI and re-initialize capture.
  4. Catch the exception and show a user-facing message to start the capture.

Example fix

// before
var cap = TaskTriggerDispatcher.GlobalGameCapture;
var frame = cap.Capture();
// after
if (TaskTriggerDispatcher.Instance().GameCapture is null)
{
    Toast.Warning("截图器未初始化");
    return;
}
var cap = TaskTriggerDispatcher.GlobalGameCapture;
Defensive patterns

Strategy: validation

Validate before calling

if (TaskTriggerDispatcher.Instance().GameCapture is null)
{
    Toast.Warning("截图器未初始化");
    return;
}

Type guard

static bool HasCapture => TaskTriggerDispatcher.Instance().GameCapture is not null;

Try / catch

try { var cap = TaskTriggerDispatcher.GlobalGameCapture; }
catch (Exception ex) { Log.Warning("截图器未初始化: {Msg}", ex.Message); }

Prevention

When it happens

Trigger: Accessing TaskTriggerDispatcher.GlobalGameCapture after the dispatcher singleton was created but before the capture backend (GameCapture) was set, or after it was released. Typical when capture startup failed or was cancelled.

Common situations: Starting a task that needs frames before the capture backend is attached; capture initialization failed silently and left GameCapture null; the user closed the capture but kept the dispatcher alive.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/f73fd7561ca00863. Report an issue: GitHub.