godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.99k stars 21.16k forks source link

`DISABLE_MANGOHUD` etc environment variables are unconditionally unset #73929

Open follower opened 1 year ago

follower commented 1 year ago

Godot version

v4.0.rc5.official.6296b4600

System information

N/A

Issue description

The following environment variables are unset unconditionally in certain circumstances:

This is due to https://github.com/godotengine/godot/commit/12817543a9e55b132da252a55f08ab11f9a02724 which was part of https://github.com/godotengine/godot/pull/71515.

In the process of creating this issue I discovered this was mentioned as a known issue in a comment on the original PR https://github.com/godotengine/godot/pull/71515/commits/12817543a9e55b132da252a55f08ab11f9a02724#r1073217244 but I hadn't seen it previously because the comment isn't visible when viewing the commit directly via https://github.com/godotengine/godot/commit/12817543a9e55b132da252a55f08ab11f9a02724.

While I recognize this isn't a high priority issue (so feel free to close/low-prio it) I decided I'd finish creating an issue so that at least if some other weirdo :D notices/runs into this in future they might find a pointer to the original comment.

Also, FWIW, this also leads to differing behaviour when using --headless (e.g. with --script) via an editor binary vs export template binary but I don't know if this is a general known issue or not. [Update: Oh, actually, turns out export template binaries won't run a --script script without an associated .pck or project path. I think I'm going to stop now. :D ]

Steps to reproduce

  1. Use one or other of these scripts as described:
# Save this script as `test-env-unset.gd`.
# Run this via `--script`.
extends MainLoop

func _init():
    prints("hello")
    prints("DISABLE_MANGOHUD:", OS.get_environment("DISABLE_MANGOHUD"))
    prints("SHELL:", OS.get_environment("SHELL"))

or:

# Attach this to a node in the default scene in a project.
extends Node2D

func _init():
    prints("hello")
    prints("DISABLE_MANGOHUD:", OS.get_environment("DISABLE_MANGOHUD"))
    prints("SHELL:", OS.get_environment("SHELL"))
  1. (On Linux) Run either script while e.g. DISABLE_MANGOHUD is set:
$ DISABLE_MANGOHUD=3 /<path>/Godot_v4.0-rc5_linux.x86_64 --headless --quit --script test-env-unset.gd
Godot Engine v4.0.rc5.official.6296b4600 - https://godotengine.org

hello
DISABLE_MANGOHUD: 1
SHELL: /bin/bash

Depending on whether the binary is an editor binary (or other tools-enabled binary) or export template binary (and whether script is standalone or scene attached and whether or not --headless is used and whether or not a project path is given) the output will contain one of three possible outputs:

DISABLE_MANGOHUD: 1
DISABLE_MANGOHUD: 3
DISABLE_MANGOHUD:

(Also, to view the behaviour before this change was made Godot_v4.0-beta12_linux.x86_64 can be used.)

Minimal reproduction project

N/A

P.S. Thanks to everyone for all their work on 4.0. :)

Calinou commented 1 year ago

[Update: Oh, actually, turns out export template binaries won't run a --script script without an associated .pck or project path. I think I'm going to stop now. :D ]

You can create an empty PCK using touch <binary name>.pck as a workaround. This should likely be fixed though.