From 971cbf8ba12e00b8461fbd2afe5b8f793361cf67 Mon Sep 17 00:00:00 2001 From: Eliasepfl Date: Wed, 5 Aug 2026 15:01:27 -0400 Subject: [PATCH] Pass --fixed-fps as two argv tokens --fixed-fps is a Godot engine argument and takes its value as a separate token, but it was appended as one string ("--fixed-fps 60"). Popen passes argv as a list, so Godot receives a single unknown parameter and aborts with "Couldn't detect whether to run the editor, the project manager or a specific project" instead of starting the game. Passing any framerate to GodotEnv is therefore broken today. The argv construction moves to GodotEnv._build_launch_cmd so it can be tested without a game binary. Everything else keeps the --key=value form the plugin parses. --- godot_rl/core/godot_env.py | 40 +++++++++++++++++++++++----- tests/test_launch_cmd.py | 54 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 tests/test_launch_cmd.py diff --git a/godot_rl/core/godot_env.py b/godot_rl/core/godot_env.py index 72ed8948..05c82764 100644 --- a/godot_rl/core/godot_env.py +++ b/godot_rl/core/godot_env.py @@ -7,7 +7,7 @@ import time from collections import OrderedDict from sys import platform -from typing import Optional +from typing import List, Optional import numpy as np from gymnasium import spaces @@ -291,8 +291,8 @@ def _close(self): print("exit was not clean, using atexit to close env") self.close() - def _launch_env( - self, + @staticmethod + def _build_launch_cmd( env_path, port, show_window, @@ -301,8 +301,11 @@ def _launch_env( action_repeat, speedup, **kwargs, - ): - # --fixed-fps {framerate} + ) -> List[str]: + """Build the argv list used to launch the Godot game. + + Kept separate from the actual launch so it can be unit tested without a game binary. + """ path = convert_macos_path(env_path) if platform == "darwin" else env_path launch_cmd = [path] @@ -313,7 +316,8 @@ def _launch_env( launch_cmd.append("--disable-render-loop") launch_cmd.append("--headless") if framerate is not None: - launch_cmd.append(f"--fixed-fps {framerate}") + # --fixed-fps is a Godot engine argument, it expects its value as a separate token + launch_cmd.extend(["--fixed-fps", str(framerate)]) if action_repeat is not None: launch_cmd.append(f"--action_repeat={action_repeat}") if speedup is not None: @@ -322,6 +326,30 @@ def _launch_env( for key, value in kwargs.items(): launch_cmd.append(f"--{key}={value}") + return launch_cmd + + def _launch_env( + self, + env_path, + port, + show_window, + framerate, + seed, + action_repeat, + speedup, + **kwargs, + ): + launch_cmd = self._build_launch_cmd( + env_path, + port, + show_window, + framerate, + seed, + action_repeat, + speedup, + **kwargs, + ) + self.proc = subprocess.Popen( launch_cmd, start_new_session=True, diff --git a/tests/test_launch_cmd.py b/tests/test_launch_cmd.py new file mode 100644 index 00000000..13ab2db6 --- /dev/null +++ b/tests/test_launch_cmd.py @@ -0,0 +1,54 @@ +from godot_rl.core.godot_env import GodotEnv + + +def build(**overrides): + kwargs = dict( + env_path="game.x86_64", + port=11008, + show_window=True, + framerate=None, + seed=0, + action_repeat=None, + speedup=None, + ) + kwargs.update(overrides) + return GodotEnv._build_launch_cmd(**kwargs) + + +def test_no_argument_carries_an_embedded_space(): + # Popen receives argv as a list, so a token like "--fixed-fps 60" reaches Godot as a + # single unknown parameter and the engine aborts at startup. + cmd = build(framerate=60, action_repeat=4, speedup=8, show_window=False) + assert all(" " not in arg for arg in cmd[1:]) + + +def test_fixed_fps_is_split_into_two_tokens(): + cmd = build(framerate=60) + assert "--fixed-fps" in cmd + assert cmd[cmd.index("--fixed-fps") + 1] == "60" + + +def test_framerate_none_omits_the_flag(): + assert not any("fixed-fps" in arg for arg in build()) + + +def test_plugin_arguments_keep_the_equals_form(): + cmd = build(port=11010, seed=3, action_repeat=4, speedup=8) + assert "--port=11010" in cmd + assert "--env_seed=3" in cmd + assert "--action_repeat=4" in cmd + assert "--speedup=8" in cmd + + +def test_hidden_window_adds_the_headless_flags(): + cmd = build(show_window=False) + assert "--disable-render-loop" in cmd + assert "--headless" in cmd + + +def test_extra_kwargs_are_forwarded(): + assert "--custom_arg=7" in build(custom_arg=7) + + +def test_env_path_stays_first(): + assert build()[0] == "game.x86_64"