From 2f4c8a7756dcb5ef1585de541d2610ba08bfdb69 Mon Sep 17 00:00:00 2001 From: Natalie Date: Tue, 12 May 2026 11:44:43 -0700 Subject: [PATCH] =?UTF-8?q?feat(@projects/@magic-civilization):=20?= =?UTF-8?q?=E2=9C=A8=20add=20weston-headless=20backend=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- scripts/p2-72-option-b-render.sh | 33 +++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/scripts/p2-72-option-b-render.sh b/scripts/p2-72-option-b-render.sh index 0173a7f0..a1b6b987 100755 --- a/scripts/p2-72-option-b-render.sh +++ b/scripts/p2-72-option-b-render.sh @@ -49,9 +49,36 @@ echo "Seed=$CP_SEED Players=$CP_PLAYERS Map=$CP_MAP_SIZE Turns=$CP_TURNS" echo "Output (in sandbox): $CP_OUTPUT_DIR" echo "Log: $LOG_FILE" -# Pure-headless — no Wayland (renderer draws into the headless framebuffer, -# Image.save_png reads from get_viewport().get_texture()). +# Headless rendering: pure --headless uses Godot's dummy rendering server, +# which returns null from get_viewport().get_texture() — Image.save_png +# fails. We need a real GL context, so use weston-headless as a Wayland +# host for the flatpak sandbox. Mirrors tools/autoplay-batch.sh --weston. +if ! command -v weston >/dev/null 2>&1; then + echo "ERROR: weston not installed — cannot render screenshots headlessly" >&2 + exit 2 +fi +WESTON_SOCKET="p2-72-option-b-$$" +echo "Starting weston (headless backend, socket=$WESTON_SOCKET)..." +WESTON_LOG="/tmp/p2-72-option-b-weston.log" +weston --backend=headless --no-config --socket="$WESTON_SOCKET" \ + --width=1920 --height=1080 \ + >"$WESTON_LOG" 2>&1 & +WESTON_PID=$! +sleep 1.5 +if ! kill -0 "$WESTON_PID" 2>/dev/null; then + echo "ERROR: weston failed to launch — see $WESTON_LOG" >&2 + tail -20 "$WESTON_LOG" >&2 + exit 3 +fi +trap 'kill $WESTON_PID 2>/dev/null; wait $WESTON_PID 2>/dev/null' EXIT + +XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}" \ timeout "$CP_TIMEOUT_SEC" flatpak run --user \ + --filesystem=home \ + --socket=wayland \ + --unset-env=DISPLAY \ + --env=WAYLAND_DISPLAY="$WESTON_SOCKET" \ + --filesystem=xdg-run/${WESTON_SOCKET} \ --env=CP_SEED="$CP_SEED" \ --env=CP_PLAYERS="$CP_PLAYERS" \ --env=CP_CLAUDE_SLOT="$CP_CLAUDE_SLOT" \ @@ -63,7 +90,7 @@ timeout "$CP_TIMEOUT_SEC" flatpak run --user \ --env=MC_USE_PROCEDURAL_SPRITES="1" \ org.godotengine.Godot \ --path "$PROJECT_DIR/src/game" \ - --headless \ + --display-driver wayland \ --rendering-driver opengl3 \ --rendering-method gl_compatibility \ res://engine/scenes/tests/claude_vs_ai_render_proof.tscn \