From 8c9f66ac0617c8b9239bb0a837c1035bfc1ece3e Mon Sep 17 00:00:00 2001 From: Nik Afiq Date: Fri, 6 Nov 2026 21:17:26 +0900 Subject: [PATCH] fix(driver): disable NVIDIA page flipping before launching BA With page flipping on, BA's fullscreen window never puts a new frame on screen on nik-gpu and sits frozen on "Initialize Catalog..." until login.py's timeout kills it. It only worked during a Moonlight session, because Sunshine's NvFBC capture makes the driver copy frames instead. The setting resets on reboot or X restart, so launch_game() applies AllowFlipping=0 before every launch. A failure is reported but not raised, since login.py already fails the run loudly if the game never gets past loading. setup.sh now checks for nvidia-settings, and CLAUDE.md lists it as a runtime dependency. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 1 + ba_auto/driver.py | 22 ++++++++++++++++++++++ setup.sh | 4 ++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index a023c94..6e5956f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -291,6 +291,7 @@ Required now: - `scrot` - `python3` - `curl` (confirmed present at `/usr/bin/curl`) -- only used by `ba_cron_run.sh`'s optional Discord alerting, not by any Python task/driver code +- `nvidia-settings` (confirmed present at `/usr/bin/nvidia-settings`) -- `driver.launch_game()` runs `nvidia-settings -a AllowFlipping=0` before every launch. Without it, BA froze on "Initialize Catalog..." on every unattended launch from 2026-10-26 to 10-29, and only worked while a Moonlight session was connected (Sunshine's NvFBC capture stops the driver from flipping). The setting resets on reboot, which is why it's re-applied each launch. See `driver.disable_page_flipping()`. Required Python packages: diff --git a/ba_auto/driver.py b/ba_auto/driver.py index d11e542..fa159d8 100644 --- a/ba_auto/driver.py +++ b/ba_auto/driver.py @@ -170,12 +170,34 @@ def kill_game(force=False): run_command(["pkill", *signal_args, "-f", config.GAME_PROCESS_NAME], check=False) +def disable_page_flipping(): + # Real incident (2026-10-26 to 10-29): with the NVIDIA driver's page + # flipping on, BA's fullscreen window on nik-gpu never puts a new frame + # on screen -- it sits frozen on "Initialize Catalog..." until login.py's + # timeout kills it -- unless a Moonlight session is connected, because + # Sunshine's NvFBC capture makes the driver copy frames instead of flip. + # Confirmed by A/B: frozen on every launch with AllowFlipping=1, title + # screen with no input and home in 47s via login with AllowFlipping=0. + # It's a runtime X setting that a reboot or X restart resets to 1, so + # it's re-applied before every launch instead of set once by hand. + # A failure is reported, not raised: the launch can still work (e.g. + # during a Moonlight session), and login.py fails the run loudly if not. + result = run_command( + ["nvidia-settings", "-a", "AllowFlipping=0"], + check=False, capture_output=True, text=True, + ) + if result.returncode != 0: + print(f"[driver] warning: couldn't disable NVIDIA page flipping (exit {result.returncode}) -- " + f"BA may freeze on its loading screen: {result.stderr.strip()}") + + def launch_game(): # The launch script (see config.GAME_LAUNCH_SCRIPT) blocks until the # game process exits, by design (it's meant to be run as a foreground # session launcher) -- Popen + start_new_session=True detaches it so # this process can keep polling for the window instead of hanging for # the whole play session. + disable_page_flipping() subprocess.Popen( [config.GAME_LAUNCH_SCRIPT], env=config.ENV, diff --git a/setup.sh b/setup.sh index f70c709..2dd09d4 100755 --- a/setup.sh +++ b/setup.sh @@ -17,7 +17,7 @@ VENV_DIR="$HOME/.venvs/ba-auto-daily" echo "== Checking host tools ==" missing=0 -for cmd in xdotool scrot; do +for cmd in xdotool scrot nvidia-settings; do if ! command -v "$cmd" >/dev/null 2>&1; then echo "MISSING: $cmd (install with your package manager, e.g. sudo apt install $cmd)" missing=1 @@ -27,7 +27,7 @@ if [ "$missing" = 1 ]; then echo "Install the missing tool(s) above, then re-run this script." exit 1 fi -echo "xdotool, scrot: OK" +echo "xdotool, scrot, nvidia-settings: OK" if ! command -v tesseract >/dev/null 2>&1; then echo "MISSING: tesseract (OCR engine binary -- e.g. sudo apt install tesseract-ocr)"