noxworld-dev / opennox

OpenNox main repository.
GNU General Public License v3.0
463 stars 25 forks source link

Ubuntu 22.04 - libGL error #573

Closed m0glan closed 1 year ago

m0glan commented 1 year ago

Hi, I've been trying to run the OpenNox snap on Ubuntu 22.04 but it is crashing on launch. Launching it via the console reveals the error:

opennox -data /home/vlad/Games/Heroic/Nox
2022/12/18 19:57:57 [version]: version: v1.8.11 ()
2022/12/18 19:57:57 [version]: GET https://ghcr.io/token?scope=repository%3Anoxworld-dev%2Fopennox%3Apull
2022/12/18 19:57:57 [config]: using file: "/home/vlad/snap/opennox/common/opennox.yml"
2022/12/18 19:57:57 [path]: setting data dir to: "/home/vlad/Games/Heroic/Nox"
libGL error: MESA-LOADER: failed to open radeonsi (search paths /usr/lib/i386-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri)
libGL error: failed to load driver: radeonsi
libGL error: MESA-LOADER: failed to open swrast (search paths /usr/lib/i386-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri)
libGL error: failed to load driver: swrast
X Error:  GLXBadContext
  Request Major code 149 (GLX)
  Request Minor code 6 ()
  Error Serial #101
  Current Serial #100

Do you happen to know what causes this? I'm using the Heroic installation of Nox, but tried Lutris and that did not work either. Doing some research on the internet I tried a few thinngs like sudo apt-get install -y mesa-utils libgl1-mesa-glx or sudo apt install --reinstall libgl1-mesa-dri but didn't fix the problem.

Thanks and good job on keeping one of my favorite games alive.

dennwc commented 1 year ago

Not 100% sure, but it may require i386 versions of some of the GL packages. Need to check that on a clean Ubuntu install.

In the meantime, here's the list of packages we use for the build. Maybe installing those will help.

m0glan commented 1 year ago

I tried installing the dependencies, but the result is the same. Will try a clean installation when I some time. By the way, I thought packaging formats like snaps come bundled with all the dependencies, right? I can even find the ones that the error is referring to in /snap/opennox/118/lib/i386-linux-gnu.

Here's something else I found on the topic, but for another game: https://steamcommunity.com/app/1066780/discussions/0/1740010344363244243/. Not sure if there is an equivalent to doing this for OpenNox.

I also tried running opennox and opennox.hd with sudo, but I'm getting:

2022/12/19 07:18:44 [path]: setting data dir to: "/home/vlad/Games/Heroic/Nox"
failed to load strings file: open nox.csf: permission denied

I tried changing the permissions of nox.csf like this sudo chmod u=rwx,g=rwx,o=rwx /home/vlad/Games/Heroic/Nox/nox.csf but that did not fix the issue (I'm still a bit of a noob when it comes to Linux).

m0glan commented 1 year ago

Small update, after doing a clean re-install of Ubuntu 22.04 the issue persists (Lutris Nox install).

dennwc commented 1 year ago

Yes, Snap usually bundles everything, but I think it's not the same for the drivers. It has some "bridge" to the host that runs GL library installed on the host. At least it's my understanding, I may be wrong.

It's interesting that the error changes with sudo. But it looks like it fails even earlier with it, right?

Thank you for confirming that clean install fails as well. I will need to find time to look into it. Maybe indeed something is missing from our Snap package.

m0glan commented 1 year ago

But it looks like it fails even earlier with it, right? That's my guess as well, it fails because of a lack of permission so probably before.

Thank you for looking into it, if any help needed testing let me know

Evengard commented 1 year ago

I kinda remember this bug, afaik it was indeed a problem of i386/x64 compat. Unfortunately, I think it was even worse than that - installing the i386 libs was overriding the x64 ones, and the end result was not working either.

We really should get rid of the C code or at least make a possibility to compile in "pseudo-x64", the x86 compat is worse by the day.

ezequielv commented 1 year ago

I've got the same error today, and I am not convinced that system libraries (missing) is the issue. I suspect it's a snap (package) configuration issue.

I've got this error when running from an X terminal:

$ LIBGL_DEBUG=verbose opennox
2022/12/24 00:31:59 [version]: version: v1.8.11 ()                                                                                                                                                                                            
2022/12/24 00:31:59 [version]: GET https://ghcr.io/token?scope=repository%3Anoxworld-dev%2Fopennox%3Apull                                                                                                                                     
2022/12/24 00:31:59 [config]: using file: "/home/{myusername}/snap/opennox/common/opennox.yml"                                                                                                                                                     
2022/12/24 00:31:59 [path]: setting data dir to: "/home/{myusername}/Games/wine/{...}/drive_c/GOG Games/Nox"                                                                                                                        
libGL: Can't open configuration file /etc/drirc: No such file or directory.                                                                                                                                                                   
libGL: Can't open configuration file /home/{myusername}/snap/opennox/118/.drirc: No such file or directory.                                                                                                                                        
libGL: Can't open configuration file /etc/drirc: No such file or directory.                                                                                                                                                                   
libGL: Can't open configuration file /home/{myusername}/snap/opennox/118/.drirc: No such file or directory.                                                                                                                                        
libGL: pci id for fd 11: 8086:0412, driver i965                                                                                                                                                                                               
libGL: MESA-LOADER: failed to open /usr/lib/i386-linux-gnu/dri/i965_dri.so: /usr/lib/i386-linux-gnu/dri/i965_dri.so: cannot open shared object file: No such file or directory                                                                
libGL: MESA-LOADER: failed to open \$${ORIGIN}/dri/i965_dri.so: \$${ORIGIN}/dri/i965_dri.so: cannot open shared object file: No such file or directory                                                                                        
libGL: MESA-LOADER: failed to open /usr/lib/dri/i965_dri.so: /usr/lib/dri/i965_dri.so: cannot open shared object file: No such file or directory                                                                                              
libGL error: MESA-LOADER: failed to open i965 (search paths /usr/lib/i386-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri)                                                                                                                         
libGL error: failed to load driver: i965                                                                                                                                                                                                      
libGL: Can't open configuration file /etc/drirc: No such file or directory.                                                                                                                                                                   
libGL: Can't open configuration file /home/{myusername}/snap/opennox/118/.drirc: No such file or directory.                                                                                                                                        
libGL: pci id for fd 11: 8086:0412, driver i965                                                                                                                                                                                               
libGL: MESA-LOADER: failed to open /usr/lib/i386-linux-gnu/dri/i965_dri.so: /usr/lib/i386-linux-gnu/dri/i965_dri.so: cannot open shared object file: No such file or directory                                                                
libGL: MESA-LOADER: failed to open \$${ORIGIN}/dri/i965_dri.so: \$${ORIGIN}/dri/i965_dri.so: cannot open shared object file: No such file or directory                                                                                        
libGL: MESA-LOADER: failed to open /usr/lib/dri/i965_dri.so: /usr/lib/dri/i965_dri.so: cannot open shared object file: No such file or directory                                                                                              
libGL error: MESA-LOADER: failed to open i965 (search paths /usr/lib/i386-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri)                                                                                                                         
libGL error: failed to load driver: i965                                                                                                                                                                                                      
libGL: MESA-LOADER: failed to open /usr/lib/i386-linux-gnu/dri/swrast_dri.so: /usr/lib/i386-linux-gnu/dri/swrast_dri.so: cannot open shared object file: No such file or directory                                                            
libGL: MESA-LOADER: failed to open \$${ORIGIN}/dri/swrast_dri.so: \$${ORIGIN}/dri/swrast_dri.so: cannot open shared object file: No such file or directory                                                                                    
libGL: MESA-LOADER: failed to open /usr/lib/dri/swrast_dri.so: /usr/lib/dri/swrast_dri.so: cannot open shared object file: No such file or directory                                                                                          
libGL error: MESA-LOADER: failed to open swrast (search paths /usr/lib/i386-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri)                                                                                                                       
libGL error: failed to load driver: swrast                                                                                                                                                                                                    
X Error:  GLXBadContext                                                                                                                                                                                                                       
  Request Major code 152 (GLX)                                                                                                                                                                                                                
  Request Minor code 6 ()                                                                                                                                                                                                                     
  Error Serial #111                                                                                                    
  Current Serial #110

Now, I've tried to find the missing i965_dri.so file in my system (linux mint based on ubuntu-20.04), and it's not there. I've got other "dri" files, but not the one the game is looking for. Every other game (native Linux, and windows games run under wine, including those using opengl, directx (with and without dxvk), etc.) is working perfectly, and xdpyinfo and xdriinfo are happy to report DRI support being enabled, so I presume my dri setup is sound, and not missing any libraries needed by applications using DRI, including libGL-based ones.

However, I've found that the snap package does include the files libGL is looking for:

$ find /snap/opennox/current/ -type d -name dri -print0 | sort -z | xargs -0rt -L 1 ls -la || echo "ERROR: $?"
ls -la /snap/opennox/current/usr/lib/i386-linux-gnu/dri 
total 261219
drwxr-xr-x 2 root root      315 Jun 29 10:51 .
drwxr-xr-x 6 root root     3264 Jun 29 10:51 ..
-rw-r--r-- 5 root root 14174240 Jun 12  2020 i915_dri.so
-rw-r--r-- 5 root root 14174240 Jun 12  2020 i965_dri.so
-rw-r--r-- 9 root root 21845760 Jun 12  2020 iris_dri.so
-rw-r--r-- 9 root root 21845760 Jun 12  2020 kms_swrast_dri.so
-rw-r--r-- 9 root root 21845760 Jun 12  2020 nouveau_dri.so
-rw-r--r-- 5 root root 14174240 Jun 12  2020 nouveau_vieux_dri.so
-rw-r--r-- 5 root root 14174240 Jun 12  2020 r200_dri.so
-rw-r--r-- 9 root root 21845760 Jun 12  2020 r300_dri.so
-rw-r--r-- 9 root root 21845760 Jun 12  2020 r600_dri.so
-rw-r--r-- 5 root root 14174240 Jun 12  2020 radeon_dri.so
-rw-r--r-- 9 root root 21845760 Jun 12  2020 radeonsi_dri.so
-rw-r--r-- 9 root root 21845760 Jun 12  2020 swrast_dri.so
-rw-r--r-- 9 root root 21845760 Jun 12  2020 virtio_gpu_dri.so
-rw-r--r-- 9 root root 21845760 Jun 12  2020 vmwgfx_dri.so

So I've tried to force the executable to use the LD_LIBRARY_PATH pointing inside the snap package, but I must be missing something (no time to dig into it right now, I'm afraid), as the snap wrapper seems to be either stripping its value, or manipulating the filesystem visible inside the snap (container?) execution environment:

$ ( d=/snap/opennox/current/usr/lib/i386-linux-gnu && LD_LIBRARY_PATH="${d}:${d}/dri:${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}}" LIBGL_DEBUG=verbose opennox ) || echo "ERROR: $?"
2022/12/24 00:57:18 [version]: version: v1.8.11 ()
2022/12/24 00:57:18 [version]: GET https://ghcr.io/token?scope=repository%3Anoxworld-dev%2Fopennox%3Apull
2022/12/24 00:57:18 [config]: using file: "/home/{myusername}/snap/opennox/common/opennox.yml"
2022/12/24 00:57:18 [path]: setting data dir to: "/home/{myusername}/Games/wine/{...}/drive_c/GOG Games/Nox"
libGL: Can't open configuration file /etc/drirc: No such file or directory.
libGL: Can't open configuration file /home/{myusername}/snap/opennox/118/.drirc: No such file or directory.
libGL: Can't open configuration file /etc/drirc: No such file or directory.
libGL: Can't open configuration file /home/{myusername}/snap/opennox/118/.drirc: No such file or directory.
libGL: pci id for fd 12: 8086:0412, driver i965                                                                        
libGL: MESA-LOADER: failed to open /usr/lib/i386-linux-gnu/dri/i965_dri.so: /usr/lib/i386-linux-gnu/dri/i965_dri.so: cannot open shared object file: No such file or directory
libGL: MESA-LOADER: failed to open \$${ORIGIN}/dri/i965_dri.so: \$${ORIGIN}/dri/i965_dri.so: cannot open shared object file: No such file or directory
libGL: MESA-LOADER: failed to open /usr/lib/dri/i965_dri.so: /usr/lib/dri/i965_dri.so: cannot open shared object file: No such file or directory
libGL error: MESA-LOADER: failed to open i965 (search paths /usr/lib/i386-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri)
libGL error: failed to load driver: i965                                                                               
libGL: Can't open configuration file /etc/drirc: No such file or directory.
libGL: Can't open configuration file /home/{myusername}/snap/opennox/118/.drirc: No such file or directory.
libGL: pci id for fd 11: 8086:0412, driver i965                                                                        
libGL: MESA-LOADER: failed to open /usr/lib/i386-linux-gnu/dri/i965_dri.so: /usr/lib/i386-linux-gnu/dri/i965_dri.so: cannot open shared object file: No such file or directory
libGL: MESA-LOADER: failed to open \$${ORIGIN}/dri/i965_dri.so: \$${ORIGIN}/dri/i965_dri.so: cannot open shared object file: No such file or directory
libGL: MESA-LOADER: failed to open /usr/lib/dri/i965_dri.so: /usr/lib/dri/i965_dri.so: cannot open shared object file: No such file or directory
libGL error: MESA-LOADER: failed to open i965 (search paths /usr/lib/i386-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri)
libGL error: failed to load driver: i965
libGL: MESA-LOADER: failed to open /usr/lib/i386-linux-gnu/dri/swrast_dri.so: /usr/lib/i386-linux-gnu/dri/swrast_dri.so: cannot open shared object file: No such file or directory
libGL: MESA-LOADER: failed to open \$${ORIGIN}/dri/swrast_dri.so: \$${ORIGIN}/dri/swrast_dri.so: cannot open shared object file: No such file or directory
libGL: MESA-LOADER: failed to open /usr/lib/dri/swrast_dri.so: /usr/lib/dri/swrast_dri.so: cannot open shared object file: No such file or directory
libGL error: MESA-LOADER: failed to open swrast (search paths /usr/lib/i386-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri) 
libGL error: failed to load driver: swrast
X Error:  GLXBadContext
  Request Major code 152 (GLX)
  Request Minor code 6 ()
  Error Serial #111
  Current Serial #110
ERROR: 1

Based on what I've shown above, I suspect it's something to do with the execution environment in which the opennox binary is run: it's either missing the configuration for the "snapified" library path (the path without /snap/opennox/current mapped as the container's / (something akin to old-days chroot-ing, I suspect)), or something else that can make it use the libraries that are bundled in the snap package. I suspect that my system libraries were loaded without really looking inside the snap package, but running through strace has not worked gone through the snap (container?) setup phase, and it's bailed out before getting as far as it should have done.

I hope this helps to get to the bottom of this problem.

dennwc commented 1 year ago

I'm currently working on adding Flatpak support (#477), and I must say it's compatibility story seems to be a lot better than for Snap.

We currently use an old Snap core version, because newer ones do not have support for x86 (aka 386) binaries. And since it's unsupported, I guess we will see more issues like this popping up.

So I'll check Snap version again once I finish with Flatpak, and if I can't figure it out, I guess we will have to drop Snap support completely (until we get a pure 64 bit build).

m0glan commented 1 year ago

Flatpak support sounds like great news, hopefully that would fix the issue. Thank you for that and thanks @ezequielv for helping with the investigation

Recydywa commented 1 year ago

I looked for solution to this problem and I've found two things that you could try.

First is using the desktop helpers.

https://forum.snapcraft.io/t/adding-opengl-gpu-support-to-a-snap/6273

If that doesn't work then maybe adding enviroment variables like some people did will work.

https://forum.snapcraft.io/t/opengl-error-mesa-loader-fails/15197

Also I don't know why you think that core18 isn't supported. It gets regular updates. The most recent one being released Mar 15, 2023.

dennwc commented 1 year ago

Hmm, maybe I misunderstood something. I got an impression that core18 is deprecated and only receives maintenance updates :thinking:

Can you try applying the changes you've linked and test if it fixes the issue?

Recydywa commented 1 year ago

core18 is based on 18.04 LTS and that will reach EOL in May 2023.

https://ubuntu.com/blog/ubuntu-18-04-eol-for-devices

And then it will probably be the end of support for that base snap. Unless it will receive ESM (Extended Security Maintenance).

I've never built a snap but I will try. Although I'm not sure if the resulting snap can be installed with the confinement. If it can't then we won't know if the changes solve the error.

vvs- commented 1 year ago

Neither Snap nor Flatpak were designed to replace system libraries and drivers. This stems from the fact that Linux kernel and X.org drivers should be compiled from exactly the same source code version as your system kernel and X.org and you only have access to a single GPU (usually). Otherwise they would not be ABI compatible.

You really should fix your system 32-bit DRI drivers first. The ultimate test should be running genuine retail Nox under Wine. And if it doesn't work either then anything else should be considered a hack and is not suitable for a generic solution.

m0glan commented 1 year ago

Neither Snap nor Flatpak were designed to replace system libraries and drivers. This stems from the fact that Linux kernel and X.org drivers should be compiled from exactly the same source code version as your system kernel and X.org and you only have access to a single GPU (usually). Otherwise they would not be ABI compatible.

You really should fix your system 32-bit DRI drivers first. The ultimate test should be running genuine retail Nox under Wine. And if it doesn't work either then anything else should be considered a hack and is not suitable for a generic solution.

In my case, GOG Nox was running fine (actually better than Windows, where it's not running at all), but not opennox.

vvs- commented 1 year ago

Fine. Then it's probably something else.

But I'm still cautious about GoG version. Why there are Windows XP, CPU 1.8 GHz and 512 MB RAM requirements, while original Nox used to run fine under Windows 98 and ordinary Pentiums of the day? In fact it didn't even require D3D at all and just plain SVGA was enough. I might be missing something obvious.

vvs- commented 1 year ago

Hmm...

Having said all that I didn't realize at first that genuine Nox shouldn't use DRI drivers at all. Then you obviously won't see that problem there.

Have you tried any other 32-bit game which did use 3D graphics, e.g. Tomb Raider Chronicles or something?

Evengard commented 1 year ago

The way Opennox works is by processing the graphics and inputs through SDL instead of DirectX. And in turns SDL requires a 3D environment. Also there's a little bit of OpenGL code to make it a little bit prettier (mostly for upscaling for higher resolutions - you don't want to run your system on 1024x768 resolution, do you?). So here we are, requiring 3D env.

vvs- commented 1 year ago

I'm not sure if I understand it correctly, but just in case. I'm not complaining about opennox implementation. I'm just trying to find out what the problem could be. And it looks like it's a difference with the original implementation. Seems that original poster assumed that if original implementation works on his system then opennox should too, but this assumption is based on false premise that they are the same.

P.S. (off-topic) You bet I was running my system in 1024x768 resolution until recently. When my old CRT monitor died I was forced to buy LCD wide screen display, so now I'm running it in 1280x720. And it seems that out of the box 1920x1080 has too small fonts for my eyes. And I'm not a fan of a huge wall mounted display anyway :)

Evengard commented 1 year ago

Yep, the implementation is different. Because DirectX is not cross-platform, while SDL is.

Offtopic: you really should look into DPI settings instead of lowering your resolution ;)

vvs- commented 1 year ago

Offtopic: you really should look into DPI settings instead of lowering your resolution ;)

I did. DPI is a mess on Linux, Gnome has it hardcoded :(

m0glan commented 1 year ago

Seems that original poster assumed that if original implementation works on his system then opennox should too, but this assumption is based on false premise that they are the same.

I wasn't assuming that, I was replying to this comment:

You really should fix your system 32-bit DRI drivers first. The ultimate test should be running genuine retail Nox under Wine.

Although I guess I didn't reply 100% accurately. I am not running Nox directly with Wine, but using Heroic Launcher with the default configuration, which I'm pretty sure just uses Wine (but not sure about what tweaks it applies). Ah, the downside of gaming on Linux having become so easy is that I don't even have to learn anything anymore, stuff just works ;)

Either way, it seems like it's an issue with drivers. I haven't tried Recydywa's solution yet, but hopefully I'll get to it during the weekend. I'm a dev, but I don't work with game or graphics frameworks so this could be a good exercise ;)

Recydywa commented 1 year ago

Success!!!

I've got it working. Turns out it only needed this to be added:

environment:
      LIBGL_DRIVERS_PATH: $SNAP/usr/lib/i386-linux-gnu/dri

I've put it after the architectures part.

ezequielv commented 1 year ago

Success!!!

I've got it working. Turns out it only needed this to be added:

environment:
      LIBGL_DRIVERS_PATH: $SNAP/usr/lib/i386-linux-gnu/dri

I've put it after the architectures part.

Thank you very much for working this out! :smile:

In the meantime, I have tried the following "manual" fix, and it turns out that -at least on my machine- it works flawlessly without any further updates:

Start opennox by forcing the variable LIBGL_DRIVERS_PATH to the resolved path on the host machine where the dri directory containing the file(s) that opennox cannot find is/are:

env LIBGL_DRIVERS_PATH=/snap/opennox/current/usr/lib/i386-linux-gnu/dri opennox

Which, at least on my system, provides the "manual" expansion of the $SNAP variable in a way that does not require any tinkering with external configuration files, the filesystem inside the snap directory, etc.

Again, thank you so much for providing the (missing for me) key piece of information needed to run opennox :smile:

dennwc commented 1 year ago

@Recydywa would you mind filing a PR? :) I'll test it on my machine as well, and if it works, we can include it in the next release (and all current edge builds).

vvs- commented 1 year ago

Don't forget that it should be binary compatible: https://dri.freedesktop.org/wiki/BinaryCompatability/

m0glan commented 1 year ago

Success!!!

I've got it working. Turns out it only needed this to be added:

environment:
      LIBGL_DRIVERS_PATH: $SNAP/usr/lib/i386-linux-gnu/dri

I've put it after the architectures part.

Thanks a lot for the effort. I am now on Fedora 37 where OpenNox flatpak works out of the box, but hopefully this will benefit others

Recydywa commented 1 year ago

I saw today that the edge channel got an update in April so I thought it must have the fix for this error. I installed it and when I run the opennox.hd still got the same result.

I checked the PR and it still isn't merged after more than a week.

@dennwc did you test the change on your machine? Can you include it in the edge channel, so I could confirm that it resolves this problem?

dennwc commented 1 year ago

Sorry for the delay, We merged the PR. Didn't test it locally, but now the build will land in edge and can be tested by anyone.

Recydywa commented 1 year ago

Thank you.

The latest build v1.8.12-dev-059023c12 works.

dennwc commented 1 year ago

I'm closing the issue then, let us know if the latest build still fails on some configurations.