Xpce: crash without graphical gui

Running from an ssh session without X11 available:

Welcome to SWI-Prolog (threaded, 64 bits, version 9.3.33-26-gb078fbdf1)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

    CMake built from "/tmp/swipl-devel/build.pgo-native"

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

13 ?- spy(paxos:set_quorum).
SDL_Init() failed: No available video device
SDL_VIDEODRIVER=(null)
[PCE fatal: nil: Failed to initialize SDL
        in:     <No exception goal>
]
        <No goal>
Host stack:
     [79] pce_principal:set_pce_thread([app_name(swipl)])
     [77] pce:init_pce
     [76] '$run_init_goal'(pce:init_pce)
     [75] catch(system:'$run_init_goal'(pce:init_pce), _8684, system:'$initialization_error'(_8684, pce:init_pce, '/tmp/swipl-devel/build.pgo-native/home/xpce/prolog/lib/pce.pl':280))
     [74] catch_with_backtrace(system:'$run_init_goal'(pce:init_pce), _8684, system:'$initialization_error'(_8684, pce:init_pce, '/tmp/swipl-devel/build.pgo-native/home/xpce/prolog/lib/pce.pl':280))

Right. Pushed a fix for that. Detecting whether or not to load xpce is a bit harder now. For now, we use this:

%!  has_display is semidet.
%
%   True when we can run graphics.  Graphics are always available on
%   Windows or MacOS (although they may   appear on the main console
%   when invoked from a  remote  login).   On  Linux,  we can detect
%   ``DISPLAY`` (X11) or  ``WAYLAND_DISPLAY``   (Wayland).  We  also
%   assume we can run graphics if the ``SDL_VIDEO_DRIVER`` is set to
%   `dummy`, implying we try to run _headless_.

has_display :- current_prolog_flag(windows, true), !.
has_display :- current_prolog_flag(apple, true), !.
has_display :- getenv('WAYLAND_DISPLAY', D), D \== '', !.
has_display :- getenv('DISPLAY', D), D \== '', !.
has_display :- getenv('SDL_VIDEO_DRIVER', dummy).

And we load xpce if the flag xpce is set to true, set it up for lazy loading if the flag xpce is not set and there is a display and do not enable it if xpce is set to false.

1 Like

would this work if we (remotely) ssh into a windows/macos machine? I would suspect this would show the gui in the host machine, which is probably not wanted.

True. That is what the comments also say. I don’t know whether there is a reliable way to detect such issues. Yes, we can detect an SSH login. There could also be some non-SSH login with the same result or there could be some SSH display forwarding active. I doubt there is a 100% solution. In any case, you can run one of these to be explicit:

swipl --no-pce
swipl --pce
1 Like

I am getting the same error after the fix, but with make:


Welcome to SWI-Prolog (threaded, 64 bits, version 9.3.34-22-g656029f07)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

    CMake built from "/tmp/swipl-devel/build.pgo-native"

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

91 ?- make.
SDL_Init() failed: No available video device
SDL_VIDEODRIVER=(null)
[PCE fatal: nil: Failed to initialize SDL
        in:     <No exception goal>
]
        <No goal>
Host stack:
     [93] pce_principal:set_pce_thread([app_name(swipl)])
     [91] pce:init_pce
     [90] '$run_init_goal'(pce:init_pce)
     [89] catch(system:'$run_init_goal'(pce:init_pce), _4206, system:'$initialization_error'(_4206, pce:init_pce, '/tmp/swipl-devel/build.pgo-native/home/xpce/prolog/lib/pce.pl':280))
     [88] catch_with_backtrace(system:'$run_init_goal'(pce:init_pce), _4206, system:'$initialization_error'(_4206, pce:init_pce, '/tmp/swipl-devel/build.pgo-native/home/xpce/prolog/lib/pce.pl':280))

Odd. I can’t reproduce this. Using current git, after ssh localhost. What could I be missing?

It’s because I have:

et    :- gtrap(_).

In my swiplrc. Perhaps this autoloads something?

If you trigger autoloading, yes. gtrap/1 is trap/1 enabling the GUI. Maybe use this?

:- if(current_prolog_flag(gui, true).
et :- gtrap(_).
:- else.
et :- trap(_).
:- endif.

I pushed some changes to the code deciding on whether or not to load xpce that does not make the library available if there is no GUI context and xpce is not explicitly enabled. That should result in gtrap/1 to be undefined.

1 Like

I guess the new xpce check broke compilation, this is with a totally clean build in a new empty dir:

$ ../scripts/configure                                                                               
# Configure using
#
#     CFLAGS=" -mtune=native -march=native -mtune=native -march=native -mtune=native -march=native -mtune=native -march=native" cmake -DCMAKE_BUILD_TYPE=PGO -G Ninja  ..
#
...
[2689/2703] -- Building xpce class index
FAILED: home/xpce/prolog/lib/CLASSINDEX.pl /tmp/swipl-devel/build.pgo-native/home/xpce/prolog/lib/CLASSINDEX.pl
cd /tmp/swipl-devel/build.pgo-native/packages/xpce && /usr/bin/cmake -E env --unset=DISPLAY SDL_VIDEODRIVER=dummy /tmp/swipl-devel/build.pgo-native/src/swipl --no-packs --home=/tmp/swipl-devel/build.pgo-native/home -DSDL_VIDEODRIVER=dummy -f none -t halt -g "pce_make_library_index('/tmp/swipl-devel/build.pgo-native/home/xpce/prolog/lib')" --
ERROR: [Thread main] -g pce_make_library_index('/tmp/swipl-devel/build.pgo-native/home/xpce/prolog/lib'): catch/3: Unknown procedure: pce_make_library_index/1
[2698/2703] Generating cqldoc.tex
ninja: build stopped: subcommand failed.

Just built it without any issues. Are we on the same page? My GIT HEAD is at 0b90b8ed9983aa78fa2fff95e095e4678546e7aa.

Yes, that is the commit I have too.

I think you will be able to reproduce it if you ssh to the machine (without a gui) and try to compile.

It works fine on a machine with a gui.

You are right. There was a typo in the name of the SDL environment variable. Pushed a fix. I thought the CI would trap that, but as the CI base images are too old to support SDL3, xpce is not part of the CI :frowning: That should be fixed after Ubuntu 26.04 is released.

1 Like