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

segfault on exit on Linux #1549

Open
SiegeLord opened this issue Mar 27, 2024 · 8 comments
Open

segfault on exit on Linux #1549

SiegeLord opened this issue Mar 27, 2024 · 8 comments

Comments

@SiegeLord
Copy link
Member

This happens reliably with most examples. Exact reasons unknown.

@kris659
Copy link

kris659 commented Mar 27, 2024

  #include <stdio.h>
  #include <allegro5/allegro5.h>
  #include <allegro5/allegro_font.h>
  
  int main()
  {
      if(!al_init()){
          printf("couldn't initialize allegro\n");
          return 1;
      }
  
      ALLEGRO_DISPLAY* disp = al_create_display(640, 480);
      if(!disp){
          printf("couldn't initialize display\n");
          return 1;
      }    
      al_destroy_display(disp);
      printf("Return\n");
  
      return 0;
  }

Command: gcc test.c -o test $(pkg-config allegro-5 allegro_font-5 allegro_image-5 allegro_primitives-5 --libs --cflags)
This prints "Return" then there is a Segmentation fault.

@gusnan
Copy link
Contributor

gusnan commented Mar 27, 2024

What Linux-distro are you on? I cannot reproduce this on Debian stable, Nvidia graphics driver, nor Debian unstable, on virtualbox on the same machine, allegro from latest git in both cases. (Neither with the allegro examples, or @kris659 short code example from here).

@kris659
Copy link

kris659 commented Mar 27, 2024

I'm using Ubuntu on WSL (someone from discord is using wayland Ubuntu)

@SiegeLord
Copy link
Member Author

Ubuntu 22.04.3 LTS + AMD here + X11 here.

@gusnan
Copy link
Contributor

gusnan commented Mar 28, 2024

Yeah, I am on X11 too on both my tests, just mention it for completion (Problem seems to be both X11 and wayland though).

@SiegeLord
Copy link
Member Author

Spent a little time on this today. It's possible to bisect a crash like this to commit d0e5746, but reverting it in today's Allegro does nothing (because it crashes before it gets to it for me).

One reliable way to avoid this crash for me is to call al_destroy_display or al_uninstall_system manually. Perhaps something in GLX isn't happy to work after main exits.

@ReiquelApplegate
Copy link
Contributor

So, perhaps all we have to do is add those manual calls to the examples?

@tstoeter
Copy link
Contributor

I could reproduce this bug on Fedora 37 with Mesa 23.0.3. However, I could not reproduce this on Ubuntu 20 with Mesa 21.2.6, nor Debian 12 with Mesa 22.3.6.

I tracked down the segfault to line 732 in xdisplay.c: glXDestroyWindow(s->x11display, glx->glxwindow);

#0  0x00007ffff79ab6ae in __strcmp_sse42 () from /lib64/libc.so.6
#1  0x00007fffe95e24e5 in parseAppAttr () from /lib64/libGLX_mesa.so.0
#2  0x00007fffe956832e in doContent () from /lib64/libexpat.so.1
#3  0x00007fffe9565e84 in doProlog () from /lib64/libexpat.so.1
#4  0x00007fffe9567a5d in prologProcessor () from /lib64/libexpat.so.1
#5  0x00007fffe956bb3a in XML_ParseBuffer () from /lib64/libexpat.so.1
#6  0x00007fffe95e1d16 in parseOneConfigFile () from /lib64/libGLX_mesa.so.0
#7  0x00007fffe95e37b6 in driParseConfigFiles () from /lib64/libGLX_mesa.so.0
#8  0x00007fffe95ddbd7 in loader_get_user_preferred_fd () from /lib64/libGLX_mesa.so.0
#9  0x00007fffe95d2779 in dri3_create_screen () from /lib64/libGLX_mesa.so.0
#10 0x00007fffe95c4489 in __glXInitialize () from /lib64/libGLX_mesa.so.0
#11 0x00007fffe95c488d in __glXSetupForCommand () from /lib64/libGLX_mesa.so.0
#12 0x00007fffe95c5848 in protocolDestroyDrawable () from /lib64/libGLX_mesa.so.0
#13 0x00007fffe95c650a in glXDestroyWindow () from /lib64/libGLX_mesa.so.0
#14 0x00007ffff7e2910a in xdpy_destroy_display_hook_default (d=0x459f20, is_last=true) at /home/user/allegro5/src/x/xdisplay.c:732
#15 0x00007ffff7e293d5 in xdpy_destroy_display (d=0x459f20) at /home/user/allegro5/src/x/xdisplay.c:783
#16 0x00007ffff7d6b933 in al_destroy_display (display=0x459f20) at /home/user//allegro5/src/display.c:168
#17 0x00007ffff7e32ea4 in xglx_shutdown_system () at /home/user/allegro5/src/x/xsystem.c:149
#18 0x00007ffff7d825a8 in shutdown_system_driver () at /home/user/allegro5/src/system.c:81
#19 0x00007ffff7d72a77 in _al_run_exit_funcs () at /home/user/allegro5/src/exitfunc.c:92
#20 0x00007ffff7d82b29 in al_uninstall_system () at /home/user/allegro5/src/system.c:324
#21 0x00007ffff787915d in __run_exit_handlers () from /lib64/libc.so.6
#22 0x00007ffff78792a0 in exit () from /lib64/libc.so.6
#23 0x000000000040253d in abort_example (format=0x4040a8 "data/fixed_font.tga not found\n") at /home/user/allegro5/examples/common.c:95
#24 0x000000000040329e in init () at /home/user/allegro5/examples/ex_blit.c:232
#25 0x0000000000403398 in main (argc=1, argv=0x7fffffffda18) at /home/user/allegro5/examples/ex_blit.c:263

If I remove the whole conditional block starting in line 731, e.g. replacing it by
if (0 && (glx->glxwindow) && (glx->glxwindow != glx->window)) {
then the segfault does not occur anymore.

For my Ubuntu and Debian tests, I also checked that this conditional branch is actually run, and it exits fine.

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

No branches or pull requests

5 participants