GameScope: Properly handle empty GAMESCOPE_ARGS string #1049
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix part of #1048.
Overview
This PR fixes a crash when GameScope arguments are blank. GameScope commands have to be ended with
--
to denote the en of the arguments list. If the user manually edits the GameScope args on the Game Menu and clears them out,This case is handled correctly by the GameScope GUI, so this only applies to editing the GameScope arguments string on the Game Menu or manually editing the per-game config file.
Problem
With our GameScope args on the main menu, if they are totally empty, we set them to
$NON
. In our functiongameScopeArgs
, we give itGAMESCOPE_ARGS
(our per-game config string) and then build the GameScope arguments in a format that we can pass as a launch command, split up into an array calledGAMESCOPEARGSARR
.However, we only build
GAMESCOPEARGSARR
if the value we give togameScopeArgs
is not$NON
. This means if it is, such as in the case of having an emptyGAMESCOPE_ARGS
string, we are simply passing nothing. This is a problem, because even if no arguments are given, GameScope commands have to be terminated with--
. For SteamTinkerLaunch, blank GameScope arguments means everything after our GameScope binary (i.e. the rest of the launch command, as GameScope usually goes first) is being interpreted by GameScope as a parameter!In the case of launching Proton games, this would mean our command looks like this:
/usr/bin/gamescope /home/gaben/.local/share/Steam/steamapps/common/Proton 8.0/proton --verb=waitforexitandrun -- /path/to/game.exe
. The problem here is that there is no--
after the GameScope command, which will cause a crash.Solution
This PR fixes the above problem by checking if the arguments string given to
gameScopeArgs
is either$NON
or blank (including an empty string like' '
, just an empty string with whitespaces), and if it is, simply setGAMESCOPEARGSARR
to have--
and return early. This also removes our nestedif
logic and flattens the function a little bit.I tested a game running with Proton 9.0 (Beta) (Cookie Clicker), and a native Linux game (shapez). Both appeared to work fine, and this does not appear to impact defined GameScope arguments, so I am not seeing any regressions.
TODO: