Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GameScope: Properly handle empty GAMESCOPE_ARGS string #1049

Merged
merged 2 commits into from
Mar 6, 2024

Conversation

sonic2kk
Copy link
Owner

@sonic2kk sonic2kk commented Mar 5, 2024

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 function gameScopeArgs, we give it GAMESCOPE_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 called GAMESCOPEARGSARR.

However, we only build GAMESCOPEARGSARR if the value we give to gameScopeArgs is not $NON. This means if it is, such as in the case of having an empty GAMESCOPE_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 set GAMESCOPEARGSARR to have -- and return early. This also removes our nested if 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:

  • A little more testing
  • Shellcheck

@sonic2kk sonic2kk merged commit 62aec11 into master Mar 6, 2024
@sonic2kk sonic2kk linked an issue Mar 7, 2024 that may be closed by this pull request
@sonic2kk sonic2kk deleted the better-gamescope-empty-args-fix branch March 7, 2024 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enableing gamescope crashes games
1 participant