babalae/better-genshin-impact · error · Exception
请先启动BetterGI
Error message
请先启动BetterGI
What it means
A generic Exception thrown by the parameterless SystemControl.ActivateWindow() when TaskContext.Instance().IsInitialized is false. It is a hard precondition guard: you cannot bring the game window to the foreground before the application's core game-context has been initialized on the startup page. Unlike NormalEndException, this is a plain System.Exception, so callers must catch broadly.
Source
Thrown at BetterGenshinImpact/GameTask/SystemControl.cs:258
var gameScreenRect = GetGameScreenRect(hWnd);
var left = windowRect.Left;
var top = windowRect.Top + windowRect.Height - gameScreenRect.Height;
var right = left + gameScreenRect.Width;
var bottom = top + gameScreenRect.Height;
return new RECT(left, top, right, bottom);
}
public static void ActivateWindow(nint hWnd)
{
User32.ShowWindow(hWnd, ShowWindowCommand.SW_RESTORE);
User32.SetForegroundWindow(hWnd);
}
public static void ActivateWindow()
{
if (!TaskContext.Instance().IsInitialized)
{
throw new Exception("请先启动BetterGI");
}
ActivateWindow(TaskContext.Instance().GameHandle);
}
public static void RestartApplication(string[] newArgs)
{
// 获取当前程序路径
string exePath = Process.GetCurrentProcess().MainModule.FileName;
// 构建参数字符串
var restartArgs = new List<string>(newArgs);
var instanceType = InstanceBootstrap.Current.Context.InstanceType;
if (instanceType == BetterGiInstanceType.ChildSession)
{
restartArgs.Add(CommandLineOptions.InstanceArgument);
restartArgs.Add("childSession");
}
else if (instanceType == BetterGiInstanceType.WebView)View on GitHub (pinned to a7cb36712d)
Solutions
- Start BetterGI and initialize the capture context on the startup page before calling this method.
- Guard the call site with `if (!TaskContext.Instance().IsInitialized) return;` or show a user-facing prompt.
- If you control the flow, await the initialized state before activating.
- Catch the exception at the UI boundary and show a ThemedMessageBox telling the user to start BetterGI first.
Example fix
// before
SystemControl.ActivateWindow();
// after
if (!TaskContext.Instance().IsInitialized)
{
await ThemedMessageBox.ShowAsync("提示", "请先启动BetterGI");
return;
}
SystemControl.ActivateWindow(); Defensive patterns
Strategy: validation
Validate before calling
if (!TaskContext.Instance().IsInitialized)
{
// do not call SystemControl.ActivateWindow()
return;
} Type guard
static bool IsReady => TaskContext.Instance().IsInitialized;
Try / catch
try { SystemControl.ActivateWindow(); }
catch (Exception ex) when (!TaskContext.Instance().IsInitialized)
{
Log.Warning("BetterGI 未初始化: {Msg}", ex.Message);
} Prevention
- Check TaskContext.Instance().IsInitialized before any window-control call.
- Start BetterGI on the startup page first.
- Disable UI actions that depend on the window until initialized.
When it happens
Trigger: Calling SystemControl.ActivateWindow() (no argument) before the user has started BetterGI and the capture context on the startup page. Common in features that auto-focus the game window before initialization completes.
Common situations: A scheduled task or hotkey handler invoking ActivateWindow during early startup; a feature triggered from a context menu before the screenshotter/capture was started; running a task right after launch.
Related errors
- 请先在启动页,启动截图器再使用本功能
- 请先在启动页启动BetterGI,如果已经启动请重启
- 截图器未初始化!
- 预热图片未找到: {modelType.PreHeatImagePath}
- 不在主界面,无法识别小地图坐标
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/a9275d945a8a2fc3.
Report an issue: GitHub.