Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault on WSL2 X11 Backend at pygame.display.set_mode when running as user #3260

Open
helgein opened this issue Jun 26, 2022 · 10 comments
Labels

Comments

@helgein
Copy link

helgein commented Jun 26, 2022

Environment:
Windows 11 WSL2 kernel 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 GNU/Linux

PS C:\Users\sr> wsl -l -v
  NAME      STATE           VERSION
* Debian    Running         2

pip3 installed as non root in user context.

  • Python version: Python 3.9.2
  • SDL version: 2.0.16
  • PyGame version: 2.1.2
  • Relevant hardware: X11 backend w/o accelaration as included in wsl2 under windows 11

Current behavior:
segmentation fault while running the below:

import pygame
pygame.init()
print('get_driver:', pygame.display.get_driver())
print('Info:', pygame.display.Info())
display = pygame.display.set_mode((640,480))
pygame 2.1.2 (SDL 2.0.16, Python 3.9.2)
Hello from the pygame community. https://www.pygame.org/contribute.html
get_driver: x11
Info: <VideoInfo(hw = 0, wm = 1,video_mem = 0
         blit_hw = 0, blit_hw_CC = 0, blit_hw_A = 0,
         blit_sw = 0, blit_sw_CC = 0, blit_sw_A = 0,
         bitsize  = 32, bytesize = 4,
         masks =  (16711680, 65280, 255, 0),
         shifts = (16, 8, 0, 0),
         losses =  (0, 0, 0, 8),
         current_w = 1920, current_h = 1080
>

Segmentation fault

whereas running as root works.

Expected behavior:
function to return w/o error.

@helgein helgein added the bug label Jun 26, 2022
@helgein helgein changed the title Segmentation fault on WSL2 X11 Backend at pygame.display.set_mode Segmentation fault on WSL2 X11 Backend at pygame.display.set_mode when running as user Jun 26, 2022
@ankith26
Copy link
Contributor

Hello and thanks for the bug report!
I can't reproduce this one myself under WSL2 (win11) and Ubuntu so perhaps this is something Debian specific?

Anyways, a gdb backtrace would be really helpful here, but it's not convenient to get (you might have to compile pygame yourself with -g/-ggdb flag and then run your code)

I wonder whether the issue reproduces for you if you try the latest Ubuntu on WSL (if it does, could be something hardware or driver/WSL2 kernel related)

@stepan-antonyuk
Copy link

stepan-antonyuk commented Aug 18, 2022

This is what I got after running python in gdb:

Thread 1 "python" received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) backtrace
#0  0x0000000000000000 in ?? ()
#1  0x00007ffff722f6ea in X11_Xinput2UngrabTouch (_this=_this@entry=0x555555d12f60, window=window@entry=0x555555d697b0)
    at /sdl_build/SDL2-2.0.16/src/video/x11/SDL_x11xinput2.c:385
#2  0x00007ffff722eaf1 in X11_SetWindowMouseGrab (_this=0x555555d12f60, window=0x555555d697b0, grabbed=<optimized out>)
    at /sdl_build/SDL2-2.0.16/src/video/x11/SDL_x11window.c:1639
#3  0x00007ffff71fad3c in SDL_UpdateWindowGrab (window=0x555555d697b0) at /sdl_build/SDL2-2.0.16/src/video/SDL_video.c:2744
#4  0x00007ffff71666e7 in SDL_SendWindowEvent (window=window@entry=0x555555d697b0, windowevent=windowevent@entry=12 '\f',
    data1=data1@entry=0, data2=data2@entry=0) at /sdl_build/SDL2-2.0.16/src/events/SDL_windowevents.c:167
#5  0x00007ffff71627f9 in SDL_SetKeyboardFocus (window=0x555555d697b0) at /sdl_build/SDL2-2.0.16/src/events/SDL_keyboard.c:659
#6  0x00007ffff7220ebf in X11_DispatchFocusIn (data=0x555555d698d0, _this=0x555555d12f60)
    at /sdl_build/SDL2-2.0.16/src/video/x11/SDL_x11events.c:397
#7  X11_DispatchEvent (_this=_this@entry=0x555555d12f60, xevent=xevent@entry=0x7fffffffd9a0)
    at /sdl_build/SDL2-2.0.16/src/video/x11/SDL_x11events.c:882
#8  0x00007ffff7222a9f in X11_PumpEvents (_this=0x555555d12f60) at /sdl_build/SDL2-2.0.16/src/video/x11/SDL_x11events.c:1596
#9  0x00007ffff715fe4c in SDL_PumpEvents_REAL () at /sdl_build/SDL2-2.0.16/src/events/SDL_events.c:760
#10 0x00007ffff6f7247b in pg_set_mode ()
   from /home/stepa/Projects/DSS-Engine/env/lib/python3.10/site-packages/pygame/display.cpython-310-x86_64-linux-gnu.so
#11 0x00005555556af76e in ?? ()
#12 0x00005555556a630b in _PyObject_MakeTpCall ()
#13 0x000055555569ec67 in _PyEval_EvalFrameDefault ()
#14 0x0000555555694cc6 in ?? ()
#15 0x0000555555789eb6 in PyEval_EvalCode ()
#16 0x00005555557b7318 in ?? ()
#17 0x00005555557b003b in ?? ()
#18 0x0000555555609be5 in ?? ()
#19 0x0000555555609775 in _PyRun_InteractiveLoopObject ()
#20 0x00005555557b6268 in _PyRun_AnyFileObject ()
#21 0x00005555555f54a7 in PyRun_AnyFileExFlags ()
#22 0x00005555557a6dcc in Py_RunMain ()
#23 0x000055555577ce6d in Py_BytesMain ()
#24 0x00007ffff7c83d90 in __libc_start_call_main (main=main@entry=0x55555577ce30, argc=argc@entry=1, argv=argv@entry=0x7fffffffe268)
    at ../sysdeps/nptl/libc_start_call_main.h:58
#25 0x00007ffff7c83e40 in __libc_start_main_impl (main=0x55555577ce30, argc=1, argv=0x7fffffffe268, init=<optimized out>,
    fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffe258) at ../csu/libc-start.c:392
#26 0x000055555577cd65 in _start ()

The session is like

gdb python
run
import pygame
pygame.init()
pygame.display.set_mode((400,400))
<-- crash here -->
backtrace

@stepan-antonyuk
Copy link

Sorry, just got it fixed by

sudo apt-get install libsdl2-dev

@MondoBurrito
Copy link

Sorry, just got it fixed by

sudo apt-get install libsdl2-dev

Holy hell man, THANK YOU! I was about to give up learning Pygame while in WSL. You saved me from going through the hassle of building a dedicated VM.

@ankith26
Copy link
Contributor

Hmmm, I was tempted to close this issue, but actually there is some pygame packaging bug here. Basically, the pygame binary wheel releases we do should be self-contained and not depend on users installing any extra packages. The backtrace posted is definitely going to be useful, I will try to debug this further myself in the coming days

@MondoBurrito
Copy link

Hmmm, I was tempted to close this issue, but actually there is some pygame packaging bug here. Basically, the pygame binary wheel releases we do should be self-contained and not depend on users installing any extra packages. The backtrace posted is definitely going to be useful, I will try to debug this further myself in the coming days

HI there. As a n00bie, I have no idea what you just said, but it sounds really great. Did you write Pygame? I am FINALLY getting into it now. I'm not sure where to start, but I'm currently looking for a tutorial. Thanks for chiming in!

@ankith26
Copy link
Contributor

Hello!

I have no idea what you just said, but it sounds really great.

Here on github issues we discuss the internals of pygame as we get bugs reports to fix them. As a user you don't have to bother with a lot of the C-level jargon ;)

Did you write Pygame?

Only small parts of it, yes. I'm one of the hundreds of people who have contributed code to it 😄

I am FINALLY getting into it now. I'm not sure where to start, but I'm currently looking for a tutorial.

Oh, there are many kinds of tutorials out there, and you have many options depending on which way of learning you are most comfortable in. If you are comfortable with video based learning, there are tons of good resources on youtube. There are also many pygame books and reading materials if you think vids are not for you. Be sure to check out some pygame examples (you can find some of those on this github repo too) while you are learning and get some hands on experience :)

However if you are new to pygame, I would suggest using windows natively instead of using WSL

Coming back to the topic of this issue and I did some more digging

So well, this issue is basically an SDL issue (libsdl-org/SDL#5889) fixed in SDL 2.24.x. SDL is supposed to pick all x11 extensions available at runtime, and make-do if things are missing (and in this case, SDL did not cleanly handle the case of xinput not being there at runtime). pygame users have to make sure all relevant x11 extensions are available while using x11 to get the most out of pygame (and these are not bundled into the wheels unlike other dependencies)

@MondoBurrito
Copy link

Hello!

I have no idea what you just said, but it sounds really great.

Here on github issues we discuss the internals of pygame as we get bugs reports to fix them. As a user you don't have to bother with a lot of the C-level jargon ;)

Did you write Pygame?

Only small parts of it, yes. I'm one of the hundreds of people who have contributed code to it 😄

I am FINALLY getting into it now. I'm not sure where to start, but I'm currently looking for a tutorial.

Oh, there are many kinds of tutorials out there, and you have many options depending on which way of learning you are most comfortable in. If you are comfortable with video based learning, there are tons of good resources on youtube. There are also many pygame books and reading materials if you think vids are not for you. Be sure to check out some pygame examples (you can find some of those on this github repo too) while you are learning and get some hands on experience :)

However if you are new to pygame, I would suggest using windows natively instead of using WSL

Coming back to the topic of this issue and I did some more digging

So well, this issue is basically an SDL issue (libsdl-org/SDL#5889) fixed in SDL 2.24.x. SDL is supposed to pick all x11 extensions available at runtime, and make-do if things are missing (and in this case, SDL did not cleanly handle the case of xinput not being there at runtime). pygame users have to make sure all relevant x11 extensions are available while using x11 to get the most out of pygame (and these are not bundled into the wheels unlike other dependencies)

You are a genius. It totally blows my mind that anyone can do what you just talked about in that last paragraph. it is honestly inconceivable to me that anyone could figure that out. I'm been trying to learn Python for over a year, but I am still stumped on 8kyu Katas on Codewars. Haha. Just insane how complex this world is. You are definitely an asset to this community. Thanks so much for the explanation.

@ankith26
Copy link
Contributor

Thank you for the kind words and appreciation. But it's definitely nothing as crazy as you are probably thinking RN. And there's always more to learn for me as well ;)

@ozanyurt
Copy link

ozanyurt commented Mar 5, 2023

I encountered the same error while working on a wsl2 with a conda environment. After installing the libstdcxx-ng package with conda install -c conda-forge libstdcxx-ng, the error was resolved and I was able to work without any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants