Repository: lutris/lutris

Issue:
Getting error : ValueError("invalid literal for int() with base 10: ''") when trying to download any game
### Bug description

Lutris is not allowing me to install any game. It seems like a python dependency but I cannot seem to figure out with dependency it is. Installed lutris through dnf on Fedora 35

Gives error: ValueError("invalid literal for int() with base 10: ''")  when trying to install any game.


### How to Reproduce

Steps to reproduce the behavior:
1. Go to download any game
2. Click on Install
3. See ValueError("invalid literal for int() with base 10: ''") 


### Expected behavior

Game should install.

### Log output

```shell
INFO 2022-04-13 13:10:17,716 [startup.init_lutris:173]:Starting Lutris 0.5.10WARNING

2022-04-13 13:10:17,731 [libretro.get_libretro_cores:24]:No folder at /home/veri/.local/share/lutris/runners/retroarch/INFO

2022-04-13 13:10:17,748 [startup.check_driver:57]:Using NVIDIA drivers 510.60.02 for x86_64INFO

2022-04-13 13:10:17,748 [startup.check_driver:61]:GPU: NVIDIA GeForce RTX 3060 Laptop GPUINFO

2022-04-13 13:10:17,748 [startup.check_driver:77]:GPU: 10DE:2560 17AA:3801 (nvidia drivers)INFO 2022-04-13 13:10:17,748 [startup.check_driver:77]:GPU: 1002:1638 17AA:380C (amdgpu drivers)INFO

2022-04-13 13:10:17,821 [startup.update_runtime:213]:Startup complete


DEBUG

2022-04-13 13:10:17,879 [lutriswindow.update_store:437]:Showing 0 games

2022-04-13 13:10:49,992: Starting Lutris 0.5.10

2022-04-13 13:10:50,005: Using NVIDIA drivers 510.60.02 for x86_64

2022-04-13 13:10:50,005: GPU: NVIDIA GeForce RTX 3060 Laptop GPU

2022-04-13 13:10:50,005: GPU: 10DE:2560 17AA:3801 (nvidia drivers)

2022-04-13 13:10:50,005: GPU: 1002:1638 17AA:380C (amdgpu drivers)

2022-04-13 13:10:50,052: Startup complete

2022-04-13 13:10:50,054: Fetching installer https://lutris.net/api/installers/final-fantasy-xiv-online-xivlauncher

2022-04-13 13:10:50,054: GET https://lutris.net/api/installers/final-fantasy-xiv-online-xivlauncher

2022-04-13 13:10:50,316: Showing window InstallerWindowfinal-fantasy-xiv-online

2022-04-13 13:10:52,934: Retrieving current resolution

2022-04-13 13:10:52,934: Could not retrieve the current display mode

2022-04-13 13:11:01,331: Checking if service provide extra files

2022-04-13 13:11:01,332: No service to retrieve files from

2022-04-13 13:11:02,592: ⬇ https://kamori.goats.dev/Proxy/Update/Release/Setup.exe

2022-04-13 13:11:03,631: Finished downloading https://kamori.goats.dev/Proxy/Update/Release/Setup.exe

2022-04-13 13:11:04,095: Download completed

2022-04-13 13:11:04,095: launchersetup is available

2022-04-13 13:11:04,095: All files available

2022-04-13 13:11:04,095: All files are available, continuing install

2022-04-13 13:11:04,096: Installer command: {'task': {'arch': 'win64', 'install_gecko': False, 'install_mono': False, 'name': 'create_prefix', 'prefix': '$GAMEDIR'}}

2022-04-13 13:11:04,104: Error while completing task <bound method CommandsMixin.task of <interpreter.ScriptInterpreter object at 0x7fa4d83aa540 (lutris+installer+interpreter+ScriptInterpreter at 0x561dec5156c0)>>: <class 'ValueError'> invalid literal for int() with base 10: '' File "/usr/lib/python3.10/site-packages/lutris/util/jobs.py", line 34, in target result = self.function(*args, **kwargs) File "/usr/lib/python3.10/site-packages/lutris/installer/commands.py", line 432, in task value = self._substitute(data[key]) File "/usr/lib/python3.10/site-packages/lutris/installer/interpreter.py", line 420, in _substitute return system.substitute(template_string, self._get_string_replacements()) File "/usr/lib/python3.10/site-packages/lutris/installer/interpreter.py", line 400, in _get_string_replacements "RESOLUTION_WIDTH_HEX": hex(int(self.current_resolution[0])),

2022-04-13 13:11:04,105: Last install command failed, show error

2022-04-13 13:11:18,402: Cancelling installation of FINAL FANTASY XIV OnlineTraceback (most recent call last): File "/usr/lib/python3.10/site-packages/lutris/gui/installerwindow.py", line 525, in on_destroy if self.confirm_cancel(): File "/usr/lib/python3.10/site-packages/lutris/gui/installerwindow.py", line 571, in confirm_cancel self.interpreter.revert(remove_game_dir=remove_checkbox.get_active()) File "/usr/lib/python3.10/site-packages/lutris/installer/interpreter.py", line 376, in revert self.task({"name": "winekill"}) File "/usr/lib/python3.10/site-packages/lutris/installer/commands.py", line 432, in task value = self._substitute(data[key]) File "/usr/lib/python3.10/site-packages/lutris/installer/interpreter.py", line 420, in _substitute return system.substitute(template_string, self._get_string_replacements()) File "/usr/lib/python3.10/site-packages/lutris/installer/interpreter.py", line 400, in _get_string_replacements "RESOLUTION_WIDTH_HEX": hex(int(self.current_resolution[0])),ValueError: invalid literal for int() with base 10:

''2022-04-13 13:11:18,431: Removed window InstallerWindowfinal-fantasy-xiv-online
```


### System Information

```shell
[System]
OS:              Fedora Linux 35 
Arch:            x86_64
Kernel:          5.16.18-200.fc35.x86_64
Desktop:         GNOME
Display Server:  x11

[CPU]
Vendor:          AuthenticAMD
Model:           AMD Ryzen 7 5800H with Radeon Graphics
Physical cores:  8
Logical cores:   16

[Memory]
RAM:             38.6 GB
Swap:            8.0 GB

[Graphics]
Vendor:          AMD
OpenGL Renderer: AMD RENOIR (DRM 3.44.0, 5.16.18-200.fc35.x86_64, LLVM 13.0.0)
OpenGL Version:  4.6 (Compatibility Profile) Mesa 21.3.8
OpenGL Core:     4.6 (Core Profile) Mesa 21.3.8
OpenGL ES:       OpenGL ES 3.2 Mesa 21.3.8
Vulkan:          Supported
```


### Media (optional)

_No response_

### Checklist:

- [X] I'm not asking for support with a game or the wine runner.
- [X] I have followed the above mentioned guides and have all the graphics and wine dependencies installed.
- [X] I have checked for existing issues that describe my problem prior to opening this one.
- [X] I understand that improperly formatted bug reports may be closed without explanation.


Discussion:
I see it; your system has either DBUS nor the GnomeDesktop library, so Python falls back on a LegacyDisplayManger class that isn't much good. It tries to run xrandr but for some reason finds no resolution in this output. I don't know why that is; perhaps you could post the output of running "xrandr"?

Anyway, in this case Lutris has no resolution and represents this as a resolution of "" by "" which is a bit odd, but in most places this results in "x" turning up here and there, which probably doesn't work but can be overridden.

However, the new string-replacements (for installers) for resolution blows up trying to convert "" to a hex form. It needs to defend against this input or you crash with no recourse. I'll put something together.

Installers that actually need to know the resolution will fail, possibly messily, but I think that's the minority.

[veri@fedora ~]$ xrandr
Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384
eDP connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 344mm x 193mm
   1920x1080    165.01*+
   1680x1050    165.01  
   1280x1024    165.01  
   1440x900     165.01  
   1280x800     165.01  
   1280x720     165.01  
   1024x768     165.01  
   800x600      165.01  
   640x480      165.01  
DisplayPort-0 disconnected (normal left inverted right x axis y axis)
DisplayPort-1 disconnected (normal left inverted right x axis y axis)
DP-1-0.1 connected (normal left inverted right x axis y axis)
   1920x1080     60.00 + 143.85   119.88   100.00    84.62    60.00    59.94    50.00  
   1680x1050     59.95  
   1440x900      59.89  
   1280x1024     75.02    60.02  
   1280x720      59.94    50.00  
   1024x768      75.03    70.07    60.00  
   800x600       75.00    72.19    60.32    56.25  
   720x576       50.00  
   720x480       59.94  
   640x480       75.00    72.81    59.94    59.93  
DP-1-0.2 connected (normal left inverted right x axis y axis)
   1920x1080     60.00 + 143.85   119.88   100.00    84.62    60.00    59.94    50.00  
   1680x1050     59.95  
   1440x900      59.89  
   1280x1024     75.02    60.02  
   1280x720      59.94    50.00  
   1024x768      75.03    70.07    60.00  
   800x600       75.00    72.19    60.32    56.25  
   720x576       50.00  
   720x480       59.94  
   640x480       75.00    72.81    59.94    59.93  
DP-1-0 disconnected (normal left inverted right x axis y axis)
DP-1-1 disconnected (normal left inverted right x axis y axis)
DP-1-2 disconnected (normal left inverted right x axis y axis)
DP-1-3 disconnected (normal left inverted right x axis y axis)
DP-1-4 disconnected (normal left inverted right x axis y axis)

So I ended up switch from Gnome to KDE and everything seems to be working now for some reason
Thanks for the xrandr output. It's not clear to me why it could not get your resolution from that, but I'll look into that.

I expect KDE is providing DBUS so that it no longer tries to use xrandr.
I'm having this exact issue with an installation of League of Legends. I haven't tried any other installations yet. I keep getting the same error. I've used terminal via lutris -d to read the output;

2022-04-14 16:30:11,972: Error while completing task <bound method CommandsMixin.input_menu of <interpreter.ScriptInterpreter object at 0x7f1e5c709ec0 (lutris+installer+interpreter+ScriptInterpreter at 0x5643fda1a820)>>: <class 'ValueError'> invalid literal for int() with base 10: ''
  File "/usr/lib/python3/dist-packages/lutris/util/jobs.py", line 34, in target
    result = self.function(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/lutris/installer/commands.py", line 208, in input_menu
    preselect = self._substitute(data.get("preselect", ""))
  File "/usr/lib/python3/dist-packages/lutris/installer/interpreter.py", line 420, in _substitute
    return system.substitute(template_string, self._get_string_replacements())
  File "/usr/lib/python3/dist-packages/lutris/installer/interpreter.py", line 400, in _get_string_replacements
    "RESOLUTION_WIDTH_HEX": hex(int(self.current_resolution[0])),


I'm running Pop! OS 22.04 beta. Not sure what I should do to resolve this issue. Any help would be appreciated. 
I think there is to be a point release soon, and I'm trying to get a fix for this into it. Could you post the output of 'xrandr' for you?

The underlying issue seems to be that Lutris can't interpret this properly for some reason. A second sample of 'bad xrandr' output might help me figure this out.
OK, I've done some testing using the xrandr output from @Inveritus, and I've updated my PR to tweak the xrandr code in Lutris to be more tolerant, and also  make it de-duplicate resolutions, as all the other display managers do.

As far as I can tell, the only reason it doesn't read that is that the resolution lines do not start with two spaces; Lutris is expecting that they should. If I add spaces, Lutris can read that data.

My tweaked version no longer requires the spaces; it allows leading white-space, but instead checks to see if the resolution is the first non-white-space thing on the line.

*But* I have a nasty feeling that your xrandr output actually *did* contain those initial spaces before the resolutions, and GitHub's markdown implementation stripped them. If that's right, the real problem remains a mystery.

Maybe @cryptic3481 can provide xrandr output that will shed light on this.
> But I have a nasty feeling that your xrandr output actually did contain those initial spaces before the resolutions, and GitHub's markdown implementation stripped them. 

That's correct, the xrandr output isn't in a code block. As such we shouldn't have code that parses output that xrandr can't produce.

> also make it de-duplicate resolutions, as all the other display managers do.

that's been an issue so it's good to see it resolved. Those duplicates are cause by other monitors so ideally, we would only get the resolutions of the primary monitor which shouldn't contain duplicates.

> I expect KDE is providing DBUS so that it no longer tries to use xrandr.

The only support for a DBus backend interface we have is with Mutter, that's also the only backend we have for Wayland. I don't know if there is something to get the list of resolutions in KDE/Wayland now but there wasn't one when I coded the Mutter backend.
Hmm. That's... *unconventional*. I think xrandr is a case for "Be liberal in what you accept, and conservative in what you send" 

I tried to find some documentation or a spec for what xrandr produces, and found nothing. Do you know where I can find that? Maybe I could see where the parse went wrong that way.

Or maybe @cryptic3481 can provide a clue as well. We'll see what transpires.

At this point I have no alternative scheme here, so I'll leave it until I get some new information.

Resolving patch:
diff --git a/lutris/util/graphics/xrandr.py b/lutris/util/graphics/xrandr.py
--- a/lutris/util/graphics/xrandr.py
+++ b/lutris/util/graphics/xrandr.py
@@ -4,7 +4,7 @@
 from collections import namedtuple
 
 from lutris.util.linux import LINUX_SYSTEM
-from lutris.util.log import logger
+from lutris.util.log import logger, logging
 from lutris.util.system import read_process_output
 
 Output = namedtuple("Output", ("name", "mode", "position", "rotation", "primary", "rate"))
@@ -16,6 +16,13 @@ def _get_vidmodes():
     return read_process_output([LINUX_SYSTEM.get("xrandr")]).split("\n")
 
 
+def _log_vidmodes(message):
+    """Write the xrandr output to the log for debugging purposes"""
+    if logger.isEnabledFor(logging.DEBUG):
+        xrandr_output = read_process_output([LINUX_SYSTEM.get("xrandr")])
+        logger.debug("%s\n%s", message, xrandr_output)
+
+
 def get_outputs():  # pylint: disable=too-many-locals
     """Return list of namedtuples containing output 'name', 'geometry',
     'rotation' and whether it is the 'primary' display."""
@@ -89,12 +96,10 @@ def get_resolutions():
             resolution_match = re.match(r".*?(\d+x\d+).*", line)
             if resolution_match:
                 resolution_list.append(resolution_match.groups()[0])
-    return resolution_list
-
-
-def get_unique_resolutions():
-    """Return available resolutions, without duplicates and ordered with highest resolution first"""
-    return sorted(set(get_resolutions()), key=lambda x: int(x.split("x")[0]), reverse=True)
+    if not resolution_list:
+        resolution_list = ['1280x720']
+        _log_vidmodes("Unable to generate resolution list from xrandr output")
+    return sorted(set(resolution_list), key=lambda x: int(x.split("x")[0]), reverse=True)
 
 
 def change_resolution(resolution):
@@ -172,7 +177,8 @@ def get_current_resolution():
                 resolution_match = re.match(r".*?(\d+x\d+).*", line)
                 if resolution_match:
                     return resolution_match.groups()[0].split("x")
-        return ("", "")
+        _log_vidmodes("Unable to find the current resolution from xrandr output")
+        return ("1280", "720")
 
     @staticmethod
     def set_resolution(resolution):


Test patch: