greenfork / nimraylib_now

The Ultimate Raylib gaming library wrapper for Nim
MIT License
151 stars 17 forks source link

NixOS: GLFW: Error: 65542 Description: GLX: Failed to load GLX #84

Closed auroraanna closed 1 year ago

auroraanna commented 2 years ago

No window comes up when I try to run my program (which uses nimraylib_now of couse). I get this error:

> nimble run          
  Verifying dependencies for snekim@0.1.0
      Info: Dependency on nimraylib_now@any version already satisfied
  Verifying dependencies for nimraylib_now@0.15.0
      Info: Dependency on regex@any version already satisfied
  Verifying dependencies for regex@0.19.0
      Info: Dependency on unicodedb@>= 0.7.2 already satisfied
  Verifying dependencies for unicodedb@0.10.0
   Building snekim/snekim using c backend
INFO: Initializing raylib 4.2
INFO: Supported raylib modules:
INFO:     > rcore:..... loaded (mandatory)
INFO:     > rlgl:...... loaded (mandatory)
INFO:     > rshapes:... loaded (optional)
INFO:     > rtextures:. loaded (optional)
INFO:     > rtext:..... loaded (optional)
INFO:     > rmodels:... loaded (optional)
INFO:     > raudio:.... loaded (optional)
WARNING: GLFW: Error: 65542 Description: GLX: Failed to load GLX
WARNING: GLFW: Failed to initialize Window
FATAL: Failed to initialize Graphic Device

We already checked in the raylib discord that it's not a fault of my hardware or drivers.

greenfork commented 1 year ago

Hey, thanks for the link to your discussion! What is the exact command executed when you run nimble run?

This is the first time I see this error and it could be connected to NixOS. If you would like to tweak your build options, you can discover your package path with nimble path nimraylib_now and there the file nimraylib_now/static_build.nim is like a "Makefile". You can also inspect the exact commands used to build raylib with nim --listCmd ... so that you have a full view of all the paths used to C compiler etc.

auroraanna commented 1 year ago

The command compiles and run my project consisting of snekim.nimble:

# Package

version       = "0.1.0"
author        = "Anna Aurora"
description   = "Snake"
license       = "LGPL-3.0-or-later"
srcDir        = "src"
bin           = @["snekim"]

# Dependencies

requires "nim >= 1.6.6"
requires "nimraylib_now"

and src/snekim.nim:

import nimraylib_now

when isMainModule:
  initWindow(1280, 720, "Hello, World!")

  while not windowShouldClose():
    beginDrawing()
    drawRectangle(100, 100, 200, 300, RED)
    endDrawing()
greenfork commented 1 year ago

Unfortunately I don't think I can help with just the information I have right now. There are some debugging techniques I have listed above that would help you to figure out the correct path to resolve it.

You can still use NimraylibNow! bindings with a dynamic library .so, see here for details. Using a system-provided Raylib library is the easiest option. By default I try to statically compile all the C code which produces some strange issues on NixOS for some reason.

auroraanna commented 1 year ago

Figured it out! Running the binary works with steam-run.

auroraanna commented 1 year ago

I didn't think of this because I ususally only try steam-run with executables where the error is zsh: no such file or directory.

auroraanna commented 1 year ago

steam-run should only be needed for development too since the error should go away when a nixpkg is created for my game.

greenfork commented 1 year ago

Okay, great to know! I'm not familiar with this steam-run so I wonder if this is going to be useful to other people as well, maybe I should put it into a troubleshooting section?

auroraanna commented 1 year ago

Would be useful to NixOS users I guess tho they might also find this issue when they get the same error.

auroraanna commented 1 year ago

Not sure :woman_shrugging: steam-run is kind of general knowledge on NixOS.

greenfork commented 1 year ago

Added to the troubleshooting section. If this "general knowledge" was not the first thing you tried to do, I guess it is not obvious enough so we better include it for future people to not stumble upon this issue and make them search for the answer.

auroraanna commented 1 year ago

So, steam-run runs something in an FHS environment which NixOS does not have by default.

auroraanna commented 1 year ago

Unfortunately I don't think I can help with just the information I have right now. There are some debugging techniques I have listed above that would help you to figure out the correct path to resolve it.

You can still use NimraylibNow! bindings with a dynamic library .so, see here for details. Using a system-provided Raylib library is the easiest option. By default I try to statically compile all the C code which produces some strange issues on NixOS for some reason.

Huh, dunno why I didn't listen to you and try shared library… it works now with raylib installed and nimble build -d:nimraylib_now_shared.

auroraanna commented 1 year ago

Maybe you could add a note to the troubleshooting that you should use shared library on NixOS?

greenfork commented 1 year ago

Great, thanks! Added.