babalae/better-genshin-impact · error · InvalidOperationException

当前不在地图界面

Error message

当前不在地图界面

What it means

Thrown by GetBigMapCenterPoint when the MapScaleButton recognition object is not found in the captured screen region. This is the precondition check confirming the game is displaying the big map UI. If the button template isn't matched, the code assumes the map screen is not open.

Source

Thrown at BetterGenshinImpact/GameTask/AutoTrackPath/TpTask.cs:2150

    private Point2f GetBigMapCenterPoint(string mapName, Point2f? expectedCenterPoint)
    {
        // 判断是否在地图界面
        using var ra = CaptureToRectArea();
        using var mapScaleButtonRa = ra.Find(GetQuickTeleportRecognitionObject("MapScaleButton", ra));
        if (mapScaleButtonRa.IsExist())
        {
            var p = RecognizeBigMapCenterPoint(mapName, ra.CacheGreyMat, expectedCenterPoint);

            if (p.IsEmpty())
            {
                throw new MapPositionNotRecognizedException("大地图特征点匹配识别位置失败");
            }

            return p;
        }
        else
        {
            throw new InvalidOperationException("当前不在地图界面");
        }
    }

    private Point2f RecognizeBigMapCenterPoint(string mapName, Mat greyMat, Point2f? expectedCenterPoint = null)
    {
        Point2f p;
        try
        {
            var map = MapManager.GetMap(mapName, _mapMatchingMethod);
            p = expectedCenterPoint is Point2f expectedCenter
                ? map.GetBigMapPosition(greyMat, map.ConvertGenshinMapCoordinatesToImageCoordinates(expectedCenter))
                : map.GetBigMapPosition(greyMat);
        }
        catch (Exception ex)
        {
            throw new MapPositionNotRecognizedException("大地图特征点匹配引发异常:" + ex.Message, ex);
        }

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Open the big map in-game (press M or the configured map key) before calling this method.
  2. Wait for the map UI to fully render before invoking.
  3. Verify the capture resolution and display scaling match the MapScaleButton template expectations.
  4. Update the MapScaleButton recognition asset if the map UI changed in a game update.
Defensive patterns

Strategy: validation

Validate before calling

// Verify the map is open before calling GetBigMapCenterPoint
using var ra = task.CaptureToRectArea();
using var btn = ra.Find(task.GetQuickTeleportRecognitionObject("MapScaleButton", ra));
if (!btn.IsExist())
{
    throw new InvalidOperationException("Big map is not open. Press M first.");
}

Try / catch

try
{
    var center = task.GetBigMapCenterPoint(mapName);
}
catch (InvalidOperationException ex) when (ex.Message == "当前不在地图界面")
{
    // Open the map and retry
}

Prevention

When it happens

Trigger: Called from GetBigMapCenterPoint(mapName, expectedCenterPoint). ra.Find(GetQuickTeleportRecognitionObject("MapScaleButton", ra)).IsExist() returns false.

Common situations: Game is on the main game screen or a different UI panel, not the big map; the map was closed or a dialog is overlaying it; map UI rendering not complete; the MapScaleButton template doesn't match due to resolution/scaling differences.

Related errors


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