NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.46k stars 13.66k forks source link

Godot: Packaging a Godot binary and running it only displays a gray window. #21743

Open sunnystormy opened 7 years ago

sunnystormy commented 7 years ago

Issue description

When running a Godot-based binary that's been packaged, a window will display, but with no content.

Steps to reproduce

Export a Godot project into a fat binary using the X11 export template (non-fat binaries won't even run). Build a package using the below "default.nix" configuration file. Replace the folder and binary names with your own. (It's interesting, because the build process never complains about anything GL-related...)

` {stdenv, libX11, libXinerama, libXcursor, libXrandr, freetype, alsaLib, libpulseaudio}:

    stdenv.mkDerivation {
        name = "shader_mats";
        src = ./shadermats.tar;

        libPath = stdenv.lib.makeLibraryPath [
            libX11
            libXinerama
            libXcursor
            libXrandr
            freetype
            alsaLib
            libpulseaudio
        ];

        phases = [ "unpackPhase" "installPhase" ];
        installPhase = ''
            mkdir -p "$out/shadermats"
            cp -r shader_mats "$out/shadermats"
            chmod +x "$out/shadermats/shader_mats"

            patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) --set-rpath "$libPath" "$out/shadermats/shader_mats"

            mkdir "$out/bin"
            ln -s "$out/shadermats/shader_mats" "$out/bin/shader_mats"
        '';
    }

`

Upon running from the command line, this error also gets displayed at the top:

ERROR: _load_settings_binary: Corrupted header in binary engine.cfb (not ECFG) At: core/globals.cpp:773.

Created a ticket in the Godot repo here: https://github.com/godotengine/godot/issues/7472

Technical details

rzetterberg commented 7 years ago

I encounter the exact same thing on my machine that is running NixOS unstable.

However, If I install Godot 2.1.1 stable inside Steam and perform the same steps inside the Steam installed Godot, then the executable works:

tetris-steam

Looking at the output of ldd they both use the same linked libraries:

Looking at steam, it seems like @abbradar has most commits in nixpkgs. Any hints on what could be different using a program inside steam?

abbradar commented 7 years ago

A program inside Steam is run in FHS user environments -- that is, something very resembling Ubuntu 12.04. You can try to run your stand-alone executable with steam-run and see if it works.

rzetterberg commented 7 years ago

Finally got some time to look deeper into this!

Found a combination that works for the two demo games I tested (tetris and minesweep). Basically the solution is to just export the game from Godot (the one installed from nixpkgs) and then create a nix expression that creates a package that contains the game binary and a script that runs the binary using steam-run (thanks @abbradar), like so:

{ stdenv, steam-run, makeWrapper }:

stdenv.mkDerivation {
    name = "minesweep-1.0";
    src = ./src;

    buildInputs = [ steam-run makeWrapper ];

    phases = [ "installPhase" ];

    installPhase = ''
        mkdir -p "$out/bin"

        cp $src/* "$out/bin/"

        chmod 755 "$out/bin/minesweep"
        chmod 755 "$out/bin/minesweep-godot-bin"

        wrapProgram $out/bin/minesweep \
         --set GODOT_BIN_PATH $out/bin/minesweep-godot-bin \
         --suffix PATH : "${steam-run}/bin"
    '';
}

Where minesweep is the script with the following content:

#!/usr/bin/env sh

steam-run "$GODOT_BIN_PATH"

And minesweep-godot-bin is the actual game binary produced by godot.

I have tested this on NixOS (17.03 channel) and here's the result I get:

$ tree
.
├── default.nix
├── shell.nix
└── src
    ├── minesweep
    └── minesweep-godot-bin

1 directory, 4 files

$ nix-build shell.nix
these derivations will be built:
  /nix/store/ir8qmkmzmxnw2vjswy4qbf85v97hgdiz-minesweep-1.0.drv
these paths will be fetched (0.25 MiB download, 1.16 MiB unpacked):
  /nix/store/69y0laqzizjycwaqivbsp273n0ag3ayi-gnumake-4.2.1
  /nix/store/8ll7qzqv4001jpj7xpa0xd5rhj7m5vsm-stdenv
  /nix/store/xx2bclrflkcvrddvp6bd3wsasqs7vsp1-paxctl-0.9
fetching path ‘/nix/store/69y0laqzizjycwaqivbsp273n0ag3ayi-gnumake-4.2.1’...
fetching path ‘/nix/store/xx2bclrflkcvrddvp6bd3wsasqs7vsp1-paxctl-0.9’...

*** Downloading ‘https://cache.nixos.org/nar/0nb28jrhwds7x5f9ha3sajdlwshdch56mk743k81phic19p6xa2b.nar.xz’ (signed by ‘cache.nixos.org-1’) to ‘/nix/store/xx2bclrflkcvrddvp6bd3wsasqs7vsp1-paxctl-0.9’...

*** Downloading ‘https://cache.nixos.org/nar/0frkf4asp5sr0znq80lij87b1qv4qa0pxpmx2qyiizg6zx0sbvfv.nar.xz’ (signed by ‘cache.nixos.org-1’) to ‘/nix/store/69y0laqzizjycwaqivbsp273n0ag3ayi-gnumake-4.2.1’...
   % Total    % Received % Xferd   A%v eTroatgae lS p e e d%   R eTciemiev e d   %T iXmfee r  d    TAivmeer a gCeu rSrpeente
d       T i m e         T i m e           T i m e     C u r r e n tD
l o a d     U p l o a d       T ot a  l       S p e n t          LDelfota d  S pUepeldo
d    T o0t a l      0S p e n t0       L e f0t     S p0e e d
100  8764  100  8764    0     0   100k      0 --:--:-- --:--:-- --:--:--  100k : - -      0   -0-:--:-- --:--:-- --:--:--     0

100  235k  100  235k    0     0  2319k      0 --:--:-- --:--:-- --:--:-- 2331k

fetching path ‘/nix/store/8ll7qzqv4001jpj7xpa0xd5rhj7m5vsm-stdenv’...

*** Downloading ‘https://cache.nixos.org/nar/13l4cgdl8ws1r73vny2yqrnsrzl5l6sxbdp2xsby1wzvwip9cp3l.nar.xz’ (signed by ‘cache.nixos.org-1’) to ‘/nix/store/8ll7qzqv4001jpj7xpa0xd5rhj7m5vsm-stdenv’...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  8120  100  8120    0     0  87942      0 --:--:-- --:--:-- --:--:-- 89230

building path(s) ‘/nix/store/3kxzqrqzswypmsybn022wkif06a5xryq-minesweep-1.0’
installing
/nix/store/3kxzqrqzswypmsybn022wkif06a5xryq-minesweep-1.0

$ result/bin/minesweep

And here's the game window:

2017-04-28-233247_1918x1161_scrot

@sunnystormy can you confirm that this works for you too, please?

Edit: Forgot to mention that shell.nix that I used has the following contents:

{ system ? builtins.currentSystem }:

let
  pkgs = import <nixpkgs> { inherit system; };
in
  pkgs.callPackage ./default.nix {
    inherit (pkgs);
  }
Mic92 commented 6 years ago

Still an issue?

delan commented 4 years ago

I ran into this issue when trying to play Hardcoded after following the usual patchelf process. @rzetterberg’s idea worked for me, though I didn’t bother writing a derivation, and I had no way to export the game because I’m not one of the authors.

  1. redownload the game to undo the changes made by patchelf
  2. chmod +x path/to/game
  3. steam-run path/to/game

Screenshot_at_2019-11-06-19-53-52

Screenshot_at_2019-11-06-20-24-41

stale[bot] commented 4 years ago

Thank you for your contributions. This has been automatically marked as stale because it has had no activity for 180 days. If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity. Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse. 3. Ask on the #nixos channel on irc.freenode.net.
nixos-discourse commented 3 years ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/godot-export-will-not-run-ldd-x-not-found/13375/3