#XCreateSimpleWindow causing segfault
25 messages · Page 1 of 1 (latest)
xopendisplay can fail and return null -> segfault?
also needs to call xclosedisplay
The problem is I see no reason that this would be failing.
what's that?
Your environment variable called DISPLAY
Did you write this code yourself?
Display *XOpenDisplay(char *display_name);
display_name Specifies the hardware display name, which determines the display and communications domain to be used. On a POSIX-conformant system, if the display_name is NULL, it defaults to the value of the DISPLAY environment variable.
-> The env var is not set in your case -> It defaults to the empty string -> That display doesn't exist -> XOpenDisplay returns NULL
https://www.x.org/releases/X11R7.5/doc/man/man3/XOpenDisplay.3.html
Sounds like ChatGPT code
I did, though it's very simplified in order to find the cause of my problem
Passing NULL into XOpenDisplay is your issue
I should mention that this code worked before, and without any change that I can remember, it stopped working. It used to be nullptr there (which also doesn't work now), but I changed it to NULL after seeing that in a tutorial.
Probably because of a change in your environment variables?
how can I set that environment variable, and how can I figure out what to set it to?
ok, found that it is indeed :0
You could just pass in ":0" into XOpenDisplay as well
that still segfaults, so it's probably some other env var that's causing the problem?
Try printing out the return value
of XOpenDisplay?
it prints 0
(passing ":0" into it)