Skip to content

py-sdl2 does not honor the DISPLAY environment variable from X Protocol #182

@drpeabody

Description

@drpeabody

The DISPLAY Environment Variable is used by all the applications that know about the X Protocol to find which X Server to connect to. SDL2 Libraries in other languages use this variable properly and work fine in case of multiple X Servers etc. However PySDL2 does not work if there is a fully functional X Sever on DISPLAY=:1 instead of DISPLAY=:0

To test this, we can run a simple virtual X Server in the background:
$ Xvfb :1 -s '-screen 0 1920x1080x24 +iglx' &

Next we can see that SDL_Init() fails:

$ export DISPLAY=:1
$ python
>>> import sdl2
>>> sdl2.SDL_Init()
-1
>>> sdl2.SDL_GetError(sdl2.SDL_INIT_EVERYTHING)
'No available video device'

In contrast, SDL works when default DISPLAY is used:

$ Xvfb :0 -s '-screen 0 1920x1080x24 +iglx' &

Next we can see that SDL_Init() fails:

$ export DISPLAY=:0
$ python
>>> import sdl2
>>> sdl2.SDL_Init(sdl2.SDL_INIT_EVERYTHING)
0
>>> sdl2.SDL_GetError()
''

This issue was found after building SDL2 from source with various combinations of build flags and after a week of wondering why SDL2 could not find the X server, as the X server logs remained empty all the while. All Applications that use X Servers respect this environment variable as it allows applications to work in scenarios where different X servers configured with different settings need to be run at the same time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions