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

i3 says "could not create graphical context" with TigerVNC on NixOS #2729

Open
ghost opened this issue Apr 6, 2017 · 26 comments
Open

i3 says "could not create graphical context" with TigerVNC on NixOS #2729

ghost opened this issue Apr 6, 2017 · 26 comments
Labels
4.13 bug help wanted reproducible A bug that has been reviewed and confirmed by a project contributor

Comments

@ghost
Copy link

ghost commented Apr 6, 2017

Output of i3 --moreversion 2>&- || i3 --version:

Binary i3 version: 4.13 (2016-11-08) © 2009 Michael Stapelberg and contributors

URL to a logfile as per http://i3wm.org/docs/debugging.html:

http://logs.i3wm.org/logs/5637337312657408.bz2

What I did:

Install tigervnc, then do

cat > ~/.vnc/xstartup <<EOF
#!/bin/sh
exec i3
EOF
chmod +x ~/.vnc/xstartup
vncserver

What I saw:

sean@loefah ~> cat .vnc/loefah:1.log                                                                      

Xvnc TigerVNC 1.7.80 - built Jan  1 1970 00:00:01
Copyright (C) 1999-2016 TigerVNC Team and many others (see README.txt)
See http://www.tigervnc.org for information on TigerVNC.
Underlying X server release 11902000, The X.Org Foundation


Thu Apr  6 16:20:19 2017
 vncext:      VNC extension running!
 vncext:      Listening for VNC connections on all interface(s), port 5901
 vncext:      created VNC server for screen 0
04/06/2017 04:20:22 PM - [libi3] ERROR: Could not create graphical context. Error code: 9. Please report this bug.
04/06/2017 04:20:22 PM - [libi3] ERROR: Could not create graphical context. Error code: 9. Please report this bug.
04/06/2017 04:20:22 PM - [libi3] ERROR: Could not create graphical context. Error code: 9. Please report this bug.
04/06/2017 04:20:22 PM - [libi3] ERROR: Could not create graphical context. Error code: 9. Please report this bug.
04/06/2017 04:20:22 PM - [libi3] ERROR: Could not create graphical context. Error code: 9. Please report this bug.
04/06/2017 04:20:22 PM - [libi3] ERROR: Could not create graphical context. Error code: 9. Please report this bug.
04/06/2017 04:20:22 PM - [libi3] ERROR: Could not create graphical context. Error code: 9. Please report this bug.
04/06/2017 04:20:22 PM - [libi3] ERROR: Could not create graphical context. Error code: 9. Please report this bug.
04/06/2017 04:20:22 PM - [libi3] ERROR: Could not create graphical context. Error code: 9. Please report this bug.
04/06/2017 04:20:22 PM - [libi3] ERROR: Could not create graphical context. Error code: 9. Please report this bug.
04/06/2017 04:20:22 PM - [libi3] ERROR: Could not create graphical context. Error code: 9. Please report this bug.
04/06/2017 04:20:22 PM - [libi3] ERROR: Could not create graphical context. Error code: 9. Please report this bug.
04/06/2017 04:20:22 PM - [libi3] ERROR: Could not create graphical context. Error code: 9. Please report this bug.
04/06/2017 04:20:22 PM - [libi3] ERROR: Could not create graphical context. Error code: 9. Please report this bug.
04/06/2017 04:20:22 PM - [libi3] ERROR: Could not create graphical context. Error code: 9. Please report this bug.
04/06/2017 04:20:22 PM - [libi3] ERROR: Could not create graphical context. Error code: 9. Please report this bug.
04/06/2017 04:20:22 PM - [libi3] ERROR: Could not create graphical context. Error code: 9. Please report this bug.
04/06/2017 04:20:22 PM - [libi3] ERROR: Could not create graphical context. Error code: 9. Please report this bug.
i3status: trying to auto-detect output_format setting
i3status: auto-detected "i3bar"
Could not grab keyboard, status = 3
[libi3] libi3/font.c Using Pango font monospace, size 8
[libi3] libi3/font.c X11 root window dictates 96.094581 DPI
[libi3] libi3/font.c Using Pango font monospace, size 8

What I expected instead:
A working VNC session using i3.

@i3bot i3bot added the 4.13 label Apr 6, 2017
@ghost
Copy link
Author

ghost commented Apr 6, 2017

It looks like this is NixOS-specific...

@nmschulte
Copy link
Contributor

nmschulte commented Apr 6, 2017

Just adding some diagnostic details.

Error code 9 is BadDrawable.

The error is logged from here: https://github.com/i3/i3/blob/next/libi3/draw_util.c#L48, after the call to create_window here: https://github.com/i3/i3/blob/next/src/x.c#L149

--

Shot in the dark as to a workaround: It's been a minute since I've used VNC, but maybe there's something going on with NixOS and not properly setting the X11 Display for the vncserver execution environment? Maybe you could play with DISPLAY= env var for the VNC execution?

@ghost
Copy link
Author

ghost commented Apr 7, 2017

If I use the default xstartup with twm, I can at least launch xterm and qutebrowser over VNC. I'm not sure what all i3 expects in its environment and if NixOS might be missing something there, though.

@ghost ghost changed the title i3 says "could not create graphical context" with TigerVNC i3 says "could not create graphical context" with TigerVNC on NixOS Apr 7, 2017
@nmschulte
Copy link
Contributor

nmschulte commented Apr 7, 2017

I tested this with Debian and i3 appears to work well in this scenario.

@sphaugh, are you able to build i3 from source? The branch in #2731 simply adds a log message based upon a wild hunch, if you're bored. Building is as simple as something like this (though I prefer to use --prefix=$HOME/.local with my configure call along with a matching $PATH) after e.g. # aptitude build-dep i3.

@ghost
Copy link
Author

ghost commented Apr 11, 2017

Awesome works over VNC same as dwm, and I was able to start an i3 session with x0vncserver from the physical machine.

Arch environment, works with vncserver locally and remotely: https://gist.github.com/bf55e9f494741e59b7cb0ea639bd7fe7
NixOS remote environment, can't x0vncserver or vncserver:
https://gist.github.com/48adc43d4fb1deed53c2c17c1adbc4a2
NixOS physical environment, can at least x0vncserver:
https://gist.github.com/a3fd4eda08d2ac843ba99fece644d59e

@ghost
Copy link
Author

ghost commented Apr 12, 2017

@nmschulte I tried building from next and didn't see your error message.

@ghost
Copy link
Author

ghost commented Apr 12, 2017

This should build from next:

diff --git a/pkgs/applications/window-managers/i3/default.nix b/pkgs/applications/window-managers/i3/default.nix
index fded295b0e..e79c543be7 100644
--- a/pkgs/applications/window-managers/i3/default.nix
+++ b/pkgs/applications/window-managers/i3/default.nix
@@ -1,18 +1,19 @@
-{ fetchurl, stdenv, which, pkgconfig, makeWrapper, libxcb, xcbutilkeysyms
-, xcbutil, xcbutilwm, xcbutilxrm, libstartup_notification, libX11, pcre, libev
-, yajl, xcb-util-cursor, coreutils, perl, pango, perlPackages, libxkbcommon
-, xorgserver, xvfb_run, dmenu, i3status }:
+{ fetchgit, stdenv, which, pkgconfig, makeWrapper, autoconf, automake, libtool,
+libxcb, xcbutilkeysyms , xcbutil, xcbutilwm, xcbutilxrm,
+libstartup_notification, libX11, pcre, libev , yajl, xcb-util-cursor,
+coreutils, perl, pango, perlPackages, libxkbcommon , xorgserver, xvfb_run,
+dmenu, i3status }:
 
 stdenv.mkDerivation rec {
   name = "i3-${version}";
   version = "4.13";
 
-  src = fetchurl {
-    url = "http://i3wm.org/downloads/${name}.tar.bz2";
-    sha256 = "12ngz32swh9n85xy0cz1lq16aqi9ys5hq19v589q9a97wn1k3hcl";
+  src = fetchgit {
+    url = https://github.com/i3/i3.git;
+    rev = "refs/heads/next";
   };
 
-  nativeBuildInputs = [ which pkgconfig makeWrapper ];
+  nativeBuildInputs = [ which pkgconfig makeWrapper autoconf automake libtool ];
 
   buildInputs = [
     libxcb xcbutilkeysyms xcbutil xcbutilwm xcbutilxrm libxkbcommon
@@ -22,6 +23,8 @@ stdenv.mkDerivation rec {
     xorgserver xvfb_run
   ];
 
+  preConfigure = "autoreconf -vfi";
+
   configureFlags = [ "--disable-builddir" ];
 
   enableParallelBuilding = true;

Maybe take a look at https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/window-managers/i3/default.nix and see if anything stands out?

@nmschulte
Copy link
Contributor

nmschulte commented Apr 12, 2017

@Airblader, I wonder if a call to xcb_request_check is expensive or such and maybe it was left out of the create_window path intentionally. It seems the xcb_create_window call is not the issue here. This is over my head at this point.

I didn't see anything in that description that stood out, except that I've never used the --disable-builddir option. I noticed the tests are disabled too.

@Airblader
Copy link
Member

I don't think the call is expensive like that; it's certainly not the reason we left it out. One thing that makes VNCs »special« is their usually limited support of X extensions. Why the issue only comes up with nixOS, though – I don't know, either.

@ghost
Copy link
Author

ghost commented Apr 12, 2017

What makes i3 different from other window managers like twm, dwm, and awesome, though? Because they all seem fine with VNC.

@ghost
Copy link
Author

ghost commented Apr 12, 2017

Tried starting vncserver as root, saw this:

Exiting due to signal.
Warning: VNC extension does not support -reset, terminating instead. Use -noreset to prevent termination.
[libi3] libi3/font.c Using Pango font monospace, size 8
[libi3] libi3/font.c X11 root window dictates 96.094581 DPI

And this is what I see starting i3 from a bare xterm:
i3-vnc

@psychon
Copy link
Contributor

psychon commented Jun 7, 2017

My usual shotgun-debugging approach would be: Can you run i3 under XTrace? For example, instead of exec i3 just do exec xtrace i3 (or x11trace if that's what the tool is called for you...)

http://logs.i3wm.org/logs/5637337312657408.bz2

Did someone look at the log file yet? There are other errors showing up in there:

04/06/2017 04:15:08 PM - main.c:xcb_check_cb:123 - X11 Error received (probably harmless)! sequence 0x293, error_code = 8
04/06/2017 04:15:08 PM - main.c:xcb_check_cb:123 - X11 Error received (probably harmless)! sequence 0x294, error_code = 3

Error 8 is BadMatch and 3 is BadWindow. Also, the difference of the sequence numbers here is just 1, so I guess the first error is an error while CreateWindow and the second one is then a following request that tried to use that window.
(Yes, these errors occur only after some GCs already errored out, but this is still interesting, even though a BadMatch can have many different reasons...)

@ghost
Copy link
Author

ghost commented Jun 15, 2017

@psychon xtrace didn't have any output, sorry.

sean@kodenine ~/.vnc> cat xstartup
#!/bin/sh
exec xtrace /home/sean/.nix-profile/bin/i3

sean@kodenine ~/.vnc> cat kodenine:1.log

Xvnc TigerVNC 1.7.80 - built Jan  1 1970 00:00:01
Copyright (C) 1999-2016 TigerVNC Team and many others (see README.txt)
See http://www.tigervnc.org for information on TigerVNC.
Underlying X server release 11902000, The X.Org Foundation


Thu Jun 15 16:44:08 2017
 vncext:      VNC extension running!
 vncext:      Listening for VNC connections on all interface(s), port 5901
 vncext:      created VNC server for screen 0
Function              File                                                  Line
--------------------------------------------------------------------------------
/run/current-system/sw/bin/xterm: cannot load font '-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso10646-1'
sean@kodenine ~/.vnc>

I tried playing with it for a little bit. I can open st and it works after I mouse click the screen, for some reason. But all other functional behavior of i3 is still borked.

@stapelberg
Copy link
Member

@sphaugh What does xtrace --version print? There are two xtrace commands, the one we mean is sometimes called x11trace.

Expected output:

% xtrace --version
xtrace version 1.3.1

Note that xtrace should be called e.g. exec xtrace -o /tmp/xtrace.log /home/sean/.nix-profile/bin/i3, then provide /tmp/xtrace.log.

I can’t reproduce the issue on a Debian system with 1.7.0. I wonder what makes this NixOS-specific.

@ghost
Copy link
Author

ghost commented Sep 18, 2017

@stapelberg
Copy link
Member

Thanks for the log.

Here’s the part where the error message in question originates:

000:<:01e8: 52: Request(1): CreateWindow depth=0x18 window=0x0040000c parent=0x00000267 x=-15 y=-15 width=10 height=10 border-width=0 class=InputOutput(0x0001) visual=0x00000178 value-list={background-pixel=0x00000000 border-pixel=0x00000000 override-redirect=true(0x01) event-mask=ButtonPress,ButtonRelease,PointerMotion,Exposure,StructureNotify,SubstructureNotify,SubstructureRedirect colormap=0x00000020}
000:<:01e9: 16: Request(2): ChangeWindowAttributes window=0x0040000c value-list={cursor=0x00400002}
000:<:01ea: 16: Request(55): CreateGC cid=0x0040000d drawable=0x0040000c values={}
000:<:01eb:  4: Request(43): GetInputFocus 
000:>:01e8:Error 8=Match: major=1, minor=0, bad=32
000:>:01e9:Error 3=Window: major=2, minor=0, bad=4194316
000:>:01ea:Error 9=Drawable: major=55, minor=0, bad=4194316

As per the request serial number, it is indeed the CreateWindow which fails. I think the bad=32 refers to the colormap=0x00000020 (0x20 == 32) which we’re setting.

Issue #2435 was the last time we talked about colormaps, I think.

Could you provide the output of xwininfo and xwininfo -frame on an xterm in one of the working window managers under your TigerVNC setup please? I’m interested in the “Colormap:” value which should be present in the output.

@stapelberg
Copy link
Member

Okay, so the colormap is 0x20 in either case, but the CreateWindow in your dwm xtrace doesn’t specify the colormap explicitly.

AFAIR, dwm is not actually a reparenting window manager, so could you post the same logs with awesome, please?

Also, do things start working once you apply the following patch to i3?

diff --git i/src/x.c w/src/x.c
index 09a60493..bfc48059 100644
--- i/src/x.c
+++ w/src/x.c
@@ -142,8 +142,8 @@ void x_con_init(Con *con) {
     mask |= XCB_CW_EVENT_MASK;
     values[3] = FRAME_EVENT_MASK & ~XCB_EVENT_MASK_ENTER_WINDOW;
 
-    mask |= XCB_CW_COLORMAP;
-    values[4] = win_colormap;
+    // mask |= XCB_CW_COLORMAP;
+    // values[4] = win_colormap;
 
     Rect dims = {-15, -15, 10, 10};
     xcb_window_t frame_id = create_window(conn, dims, con->depth, visual, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCURSOR_CURSOR_POINTER, false, mask, values);

@ghost
Copy link
Author

ghost commented Sep 29, 2017

I tried the patch and it didn't have any effect. Think I'm out of gists but I can try again later if you need logs.

@psychon
Copy link
Contributor

psychon commented Sep 30, 2017

@sphaugh (If you have not already done so), could you provide xdpyinfo output? The WM does not matter here. That's hopefully a bit easier to read than the xtrace output and perhaps xtrace is leaving something out (I'm confused about its output, see below).

A working CreateWindow from awesome:

000:<:044a: 56: Request(1): CreateWindow depth=0x18 window=0x0040001a parent=0x00000267 x=0 y=0 width=1 height=1 border-width=0 class=CopyFromParent(0x0000) visual=0x00000021 value-list={border-pixel=0x00000000 bit-gravity=NorthWest(0x01) override-redirect=true(0x01) event-mask=ButtonPress,ButtonRelease,EnterWindow,LeaveWindow,PointerMotion,Exposure,StructureNotify,SubstructureNotify,SubstructureRedirect,PropertyChange colormap=0x00000020 cursor=0x00400008}

A non-working CreateWindow from i3 which generates a Match error for the colormap:

000:<:02a3: 52: Request(1): CreateWindow depth=0x18 window=0x00400030 parent=0x00000267 x=-15 y=-15 width=10 height=10 border-width=0 class=InputOutput(0x0001) visual=0x00000178 value-list={background-pixel=0x00000000 border-pixel=0x00000000 override-redirect=true(0x01) event-mask=ButtonPress,ButtonRelease,PointerMotion,Exposure,StructureNotify,SubstructureNotify,SubstructureRedirect colormap=0x00000020}

Awesome seems to use a different visual and that's the only (relevant) difference...

awesome's visual:
{depth=24 visuals={id=0x00000021 class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff};

i3's visual:
{depth=24 visuals={id=0x00000178 class=TrueColor(0x04) bits/rgb-value=8 colormap-entries=256 red-mask=0x00ff0000 green-mask=0x0000ff00 blue-mask=0x000000ff}

Looks identical to me?!? But why does depth=24 appear twice in the list of allowed depths of the root window? And why does this server have so many apparently identical visuals?

@ghost
Copy link
Author

ghost commented Oct 2, 2017

@psychon
Copy link
Contributor

psychon commented Oct 3, 2017

Weird...

The code handling CreateWindow is here: https://cgit.freedesktop.org/xorg/xserver/tree/dix/window.c?id=f23e65f96365706c69fa781b2c6cbf3203619c9f#n761
The possible causes of BadMatch in there are:

  • non-InputOnly child of an InputOnly window
  • InputOnly window with depth or border width
  • Window not using the visual or depth of its parent, and not using a visual that is available on the given screen (not applicable here since we have only one screen and that one clearly has the used visuals, right?)
  • Trying to use no border on a window with output and a different depth than its parent
  • Having no colormap for a window with output that either has a different visual than its parent or where the parent has no colormap

None of this applies to the case we are looking at, I think.

That leaves non-hardcoded error returns.

  • The "security hook" can return any error it wants. Does anyone use that?!?
  • ChangeWindowAttributes can fail with any error. However, i3 only sets a subset of the options that awesome sets, so why would it fail?

@psychon
Copy link
Contributor

psychon commented Oct 3, 2017

OHHHH!!!!! I found it.

Both awesome and i3 use the default colormap, 0x20. However, there is this check:
https://cgit.freedesktop.org/xorg/xserver/tree/dix/window.c?id=f23e65f96365706c69fa781b2c6cbf3203619c9f#n1439
(A colormap can only be used on windows that have the same visual as the colormap)

So since the default colormap, 0x20, is created for the default visual, 0x21, the two can only be used together. However, i3 tries to use colormap 0x20 with visual 0x178. It does not matter that the two visuals are identical, the colormap 0x20 may only be used with visual 0x21.

@psychon
Copy link
Contributor

psychon commented Oct 3, 2017

And I guess it's this check in i3 which is wrong:

i3/src/x.c

Line 116 in 55bc674

if (con->depth != root_depth) {

This uses get_visualid_by_depth to find any visual with the given depth. Then it assumes that for any window having the default depth, it can use the visual that was found. However, this really should check if the window has the default visual, not the default depth.

In the case we are investigating, there are two identical visuals (no idea why) and the default visual is later in the list than its duplicate. Thus, get_visualid_by_depth(24) will always find this other visual instead of the default visual.

I'll leave writing a patch to someone actually involved with i3. Feel free to acknowledge that I might have been a tiny bit helpful. ;-)

@stapelberg
Copy link
Member

stapelberg commented Oct 4, 2017

Thank you very much for your detective work on this issue, @psychon. It’s much appreciated! Be sure to remind me to offer you a beverage of your choice when we run into each other in person :).

If anyone wants to go ahead with a pull request to address this issue, feel free. I’ll be relying on external patches for this issue.

@Airblader Airblader added help wanted reproducible A bug that has been reviewed and confirmed by a project contributor and removed needs info labels Nov 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.13 bug help wanted reproducible A bug that has been reviewed and confirmed by a project contributor
Projects
None yet
Development

No branches or pull requests

5 participants