Fix app crashes: optimize Kivy window backend and SDL drivers
- Commented out forced pygame backend (causes issues with display initialization) - Added SDL_VIDEODRIVER and SDL_AUDIODRIVER fallback chains (wayland,x11,dummy) - Limited KIVY_INPUTPROVIDERS to wayland,x11 (avoids problematic input providers) - Reduced FFMPEG_THREADS from 4 to 2 (conserves Raspberry Pi resources) - Reduced LIBPLAYER_BUFFER from 2MB to 1MB (saves memory) - Fixed asyncio event loop deprecation warning (use try/except for get_running_loop) - Better exception handling for cursor hiding These changes fix the app crashing after 30 seconds due to graphics provider issues.
This commit is contained in:
72
start.sh
72
start.sh
@@ -14,11 +14,79 @@ HEARTBEAT_FILE="$SCRIPT_DIR/.player_heartbeat"
|
||||
STOP_FLAG_FILE="$SCRIPT_DIR/.player_stop_requested"
|
||||
LOG_FILE="$SCRIPT_DIR/player_watchdog.log"
|
||||
|
||||
# Function to log messages
|
||||
# Ensure log file is writable
|
||||
if [ ! -w "$(dirname "$LOG_FILE")" ]; then
|
||||
LOG_FILE="/tmp/kivy-player-watchdog.log"
|
||||
fi
|
||||
|
||||
# Function to log messages (MUST be defined before use)
|
||||
log_message() {
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
|
||||
local msg="[$(date '+%Y-%m-%d %H:%M:%S')] $1"
|
||||
echo "$msg"
|
||||
# Try to write to log file, ignore errors if permission denied
|
||||
echo "$msg" >> "$LOG_FILE" 2>/dev/null || true
|
||||
}
|
||||
|
||||
# Load user's environment from systemd user session (most reliable method)
|
||||
# This ensures we get the proper DISPLAY/WAYLAND_DISPLAY and session variables
|
||||
load_user_environment() {
|
||||
# Try to get environment from active user session via systemctl
|
||||
local user_env
|
||||
if command -v systemctl &>/dev/null; then
|
||||
user_env=$(systemctl --user show-environment 2>/dev/null)
|
||||
if [ -n "$user_env" ]; then
|
||||
# Extract display-related variables
|
||||
echo "$user_env" | grep -E '^(DISPLAY|WAYLAND_DISPLAY|XDG_RUNTIME_DIR|DBUS_SESSION_BUS_ADDRESS)=' | while read -r line; do
|
||||
export "$line"
|
||||
done
|
||||
log_message "Loaded user environment from systemctl --user"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Fallback: detect display manually
|
||||
log_message "Falling back to manual display detection..."
|
||||
|
||||
if [ -z "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then
|
||||
# Try to detect Wayland display
|
||||
if [ -S "/run/user/$(id -u)/wayland-0" ]; then
|
||||
export WAYLAND_DISPLAY=wayland-0
|
||||
log_message "Detected Wayland display: $WAYLAND_DISPLAY"
|
||||
# Try to detect X11 display
|
||||
elif [ -S "/tmp/.X11-unix/X0" ]; then
|
||||
export DISPLAY=:0
|
||||
log_message "Detected X11 display: $DISPLAY"
|
||||
else
|
||||
# Wait for display to come up (useful for systemd or delayed starts)
|
||||
log_message "Waiting for display server to be ready (up to 30 seconds)..."
|
||||
for i in {1..30}; do
|
||||
sleep 1
|
||||
if [ -S "/run/user/$(id -u)/wayland-0" ] 2>/dev/null; then
|
||||
export WAYLAND_DISPLAY=wayland-0
|
||||
log_message "Display server detected on attempt $i: Wayland"
|
||||
return 0
|
||||
elif [ -S "/tmp/.X11-unix/X0" ] 2>/dev/null; then
|
||||
export DISPLAY=:0
|
||||
log_message "Display server detected on attempt $i: X11"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
# Verify we have a display now
|
||||
if [ -z "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then
|
||||
log_message "WARNING: No display server detected. This may cause graphics issues."
|
||||
return 1
|
||||
fi
|
||||
|
||||
log_message "Display environment ready: DISPLAY=$DISPLAY WAYLAND_DISPLAY=$WAYLAND_DISPLAY"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Load the user environment early
|
||||
load_user_environment
|
||||
|
||||
# Function to check if player is healthy
|
||||
check_health() {
|
||||
# Check if heartbeat file exists and is recent (within last 60 seconds)
|
||||
|
||||
Reference in New Issue
Block a user