babalae/better-genshin-impact · critical · Exception
尝试多次后,截图失败!
Error message
尝试多次后,截图失败!
What it means
Thrown by TaskControl.CaptureGameImage when the game-capture backend returns a null frame on the initial attempt AND on all 3 retries (30ms apart). The method first calls gameCapture?.Capture(); if Frame is null it logs '截图失败!' and retries up to 3 times; if every attempt yields a null image it throws a generic Exception. This indicates the capture source (e.g. graphics capture, window grab) is not producing frames at all.
Source
Thrown at BetterGenshinImpact/GameTask/Common/TaskControl.cs:294
if (image == null)
{
captureFrame?.Dispose();
Logger.LogWarning("截图失败!");
// 重试3次
for (var i = 0; i < 3; i++)
{
captureFrame = gameCapture?.Capture();
image = captureFrame?.Frame;
if (image != null)
{
return image;
}
captureFrame?.Dispose();
Sleep(30);
}
throw new Exception("尝试多次后,截图失败!");
}
else
{
return image;
}
}
public static Mat? CaptureGameImageNoRetry(IGameCapture? gameCapture)
{
return gameCapture?.Capture()?.Frame;
}
/// <summary>
/// 自动判断当前运行上下文中截图方式,并选择合适的截图方式返回
/// </summary>
/// <returns></returns>
public static ImageRegion CaptureToRectArea(bool forceNew = false)
{View on GitHub (pinned to a7cb36712d)
Solutions
- Ensure the game window is open, visible (not minimized), and running in a capturable mode (windowed or borderless).
- Restart the capture backend / reattach to the game window before retrying.
- Switch the configured capture method to one compatible with the current display mode.
- Check for conflicting overlays (GeForce Experience, Discord, etc.) that can break capture.
- Verify gameCapture is non-null and initialized before calling CaptureGameImage.
Defensive patterns
Strategy: retry
Validate before calling
if (gameCapture == null) throw new InvalidOperationException("截图后端未初始化");
var probe = gameCapture.Capture();
if (probe?.Frame == null) { probe?.Dispose(); throw new InvalidOperationException("截图后端无帧,请检查游戏窗口/捕获方式"); }
probe?.Dispose(); Type guard
static bool IsCaptureHealthy(IGameCapture? c) => c?.Capture()?.Frame != null;
Try / catch
try { var img = TaskControl.CaptureGameImage(gameCapture); }
catch (Exception ex) when (ex.Message.Contains("截图失败"))
{ Logger.LogError(ex, "截图持续失败,请确认游戏窗口可见且捕获方式兼容"); throw; } Prevention
- Keep the game window visible and in windowed/borderless mode.
- Re-initialize the capture backend if the window changes.
- Avoid exclusive fullscreen with incompatible capture methods.
- Disable conflicting overlays that can break graphics capture.
When it happens
Trigger: gameCapture is non-null but Capture() consistently returns a frame whose .Frame is null, or Capture() returns null. This happens when the capture backend lost its target (game window closed, capture session ended), the GPU/capture API is in a bad state, the game is minimized/fullscreen-exclusive and not capturable, or the capture method is incompatible with the current display mode.
Common situations: Game window was closed, minimized, or lost focus; capture mode (e.g. GraphicsCaptureItem) dropped the session; running in exclusive fullscreen where BitBlt/Direct3D grab fails; capture backend not initialized; another tool locked the capture; driver/overlay conflict.
Related errors
- 路径追踪任务未完全走完,判定失败,触发异常!
- 实际战斗次数({pathingTask.SuccessFight})<预期战斗次数({fightCount}),判定失败
- 识别骰子数量不正确,重试超时,停止自动打牌!
- 骰子数量与预期不符,重试次数过多,可能出现了未知错误!
- 等待对方行动超时,停止自动打牌!
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/b409eca04c66b26d.
Report an issue: GitHub.