Should've mentioned the program doesn't crash, it just calls exit(), returning 1 as exit code. This makes my automated tests fail, so to me it's as bad as a crash. Judging from the stack trace, it seems the X11 calls fail because they're happening too late in the static deinitialization phase.
#1 0x00007ffff57fe1d4 in _XDefaultIOError () from /usr/lib/x86_64-linux-gnu/libX11.so.6
#2 0x00007ffff57fe41e in _XIOError () from /usr/lib/x86_64-linux-gnu/libX11.so.6
#3 0x00007ffff57fc38b in _XReply () from /usr/lib/x86_64-linux-gnu/libX11.so.6
#4 0x00007ffff57f7aed in XSync () from /usr/lib/x86_64-linux-gnu/libX11.so.6
#5 0x00007ffff57d8810 in XCloseDisplay () from /usr/lib/x86_64-linux-gnu/libX11.so.6
#6 0x0000000004aa9b75 in (anonymous namespace)::GlobalDisplay::~GlobalDisplay (this=0x64f9d30, __in_chrg=<optimized out>) at ../../../externals/sfml/src/SFML/Window/Linux/InputImpl.cpp:47
#7 0x00007ffff5142921 in __run_exit_handlers (status=0, listp=0x7ffff54bd688, run_list_atexit=true) at exit.c:78
#8 0x00007ffff51429a5 in __GI_exit (status=<optimized out>) at exit.c:100
#9 0x00007ffff5128774 in __libc_start_main (main=0x38903f9 <main(int, char const* const*)>, argc=2, ubp_av=0x7fffffffe278, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>,
stack_end=0x7fffffffe268) at libc-start.c:258
#10 0x000000000388f865 in _start ()