You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I iterate over available monitors with events loop, nothing is returned, and attempting to call get_primary_monitor() will crash:
extern crate glium;
use glium::glutin;
fn main () {
{
let events_loop = glutin::EventsLoop::new();
let mut available_monitors_count = 0;
for i in events_loop.get_available_monitors() {
available_monitors_count += 1;
}
println!("avilable monitors count: {}", available_monitors_count); // prints '0'
let primary_monitor = events_loop.get_primary_monitor(); // crash 1
}
let events_loop = glutin::EventsLoop::new(); // crash 2
}
crash 1 with:
thread 'main' panicked at '[winit] Failed to find any x11 monitor', libcore/option.rs:916:5
If crash 1 is commented out, then code will reach crash 2 with:
thread 'main' panicked at 'Failed to call XInternAtom: XError { description: "BadRequest (invalid request code or no such operation)", error_code: 1, request_code: 140, minor_code: 42 }', libcore/result.rs:945:5
Previously the iter loop would show some available monitors, and the primary monitor would be returned, but I'm not sure exactly what has changed since the last time it worked. This is on end of life LTS Ubuntu (14.04) so it may be something out of date.
Versions of XRandR earlier than 1.5 use a different code path, but should still work. It's just, as you might guess, it tends not to get tested.
...wait, actually, what version of winit are you running? I just noticed the "BadRequest (invalid request code or no such operation)" error, which would seem to suggest a protocol issue, and distinction between XRandR 1.5 and earlier versions wasn't implemented until relatively recently.
$ xrandr --listmonitors --verbose
xrandr: unrecognized option '--listmonitors'
Try 'xrandr --help' for more information.
this seems to show some kind of display information, not sure how it's different from 'monitors':
$ xrandr -q
Screen 0: minimum 8 x 8, current 1600 x 900, maximum 16384 x 16384
VGA-0 disconnected primary (normal left inverted right x axis y axis)
LVDS-0 connected 1600x900+0+0 (normal left inverted right x axis y axis) 309mm x 174mm
1600x900 60.0*+ 40.0
DP-0 disconnected (normal left inverted right x axis y axis)
DP-1 disconnected (normal left inverted right x axis y axis)
DP-2 disconnected (normal left inverted right x axis y axis)
DP-3 disconnected (normal left inverted right x axis y axis)
DP-4 disconnected (normal left inverted right x axis y axis)
DP-5 disconnected (normal left inverted right x axis y axis)
$ xrandr -q
Screen 0: minimum 8 x 8, current 3286 x 1080, maximum 32767 x 32767
LVDS1 connected primary 1366x768+0+0 (normal left inverted right x axis y axis) 260mm x 140mm
1366x768 59.97*+
1360x768 59.96
1280x720 60.00
1024x768 60.00
1024x576 60.00
960x540 60.00
800x600 60.32 56.25
864x486 60.00
640x480 59.94
720x405 60.00
680x384 60.00
640x360 60.00
DP1 disconnected (normal left inverted right x axis y axis)
HDMI1 connected 1920x1080+1366+0 (normal left inverted right x axis y axis) 530mm x 300mm
1920x1080 60.00*+
1680x1050 59.88
1600x900 59.98
1280x1024 75.02 60.02
1280x800 59.91
1152x864 75.00
1280x720 59.97
1024x768 75.08 60.00
832x624 74.55
800x600 75.00 60.32
640x480 75.00 60.00
720x400 70.08
VGA1 disconnected (normal left inverted right x axis y axis)
VIRTUAL1 disconnected (normal left inverted right x axis y axis)
@b-r-uXRRGetScreenResources is apparently really slow, so I'm going to look into caching the monitor list and using XRRSelectInput to receive events when the state changes. That's totally unrelated to this problem; I just enjoy caching things.
Wait, really? All I did was refactor the monitor module. Well, I updated the branch to be ready for merging (besides the fact that I still need to impl Debug for MonitorId on all the other platforms) so if things still work after you pull that, I guess this is fixed.
I plan on putting out a 0.14.1 release soon, which will include this.
(Since this was so quick, I'll save the caching for future work.)
The only way it could've changed is if it's somehow a timing issue that the println! calls accidentally fixed, and since all the XRandR calls we make are synchronous, that shouldn't be possible.
It seems like it only worked once as a fluke. If you want to check, you can step your way through the commits on that branch using an interactive rebase.
Well I don't see any X11 errors printing out, but this time it detects 1 monitor, but it's not the primary monitor, and crashes when trying to get primary (I added a debug print of the 1 available monitor):
Ha, there's definitely something funky happening here. The thing is, if there's no primary monitor detected, get_primary_monitor just returns the first monitor in the list, and get_primary_monitor calls get_available_monitors internally. This means you're getting inconsistent results between calls.
I could just query the extension version instead of basing it on library availability, which is probably more correct anyway.
(and at bare minimum, an assert that monitor_count isn't negative...)
Anyway, I found the problem, and it's amusing. I pretty much never use iterators, so when I refactored, I didn't realize that calling next after calling find like that would always result in None (the previous code used two copies of the monitor list, so I'd removed one). This is much better than the conclusion that this is caused by some esoteric race condition.
Activity
francesca64 commentedon May 9, 2018
Can you tell me the output of
xrandr --version?spearman commentedon May 9, 2018
$ xrandr --version
xrandr program version 1.4.1
Server reports RandR version 1.4
francesca64 commentedon May 9, 2018
Versions of XRandR earlier than 1.5 use a different code path, but should still work. It's just, as you might guess, it tends not to get tested.
...wait, actually, what version of winit are you running? I just noticed the
"BadRequest (invalid request code or no such operation)"error, which would seem to suggest a protocol issue, and distinction between XRandR 1.5 and earlier versions wasn't implemented until relatively recently.spearman commentedon May 10, 2018
Ah, I was getting the dependency from glium which has a lagging dependency on glutin which in turn has a lagging dependncy on winit 12.0.
Updating both to use winit 14.0 does fix the 2nd panic (creating another event loop after the first has been dropped), but the 1st panic remains.
b-r-u commentedon May 10, 2018
Just another data point:
With the glium code, the following winit code and with one or two connected monitors I could not observe any crashes.
francesca64 commentedon May 10, 2018
xrandr --listmonitors --verbosemight contain some interesting information.spearman commentedon May 10, 2018
this seems to show some kind of display information, not sure how it's different from 'monitors':
b-r-u commentedon May 10, 2018
francesca64 commentedon May 10, 2018
Ah, sorry, I guess
--listmonitorsmust be a 1.5 thing.@b-r-u unless you have a burning desire to trawl through the RandR spec, I'll take a crack at fixing this.
b-r-u commentedon May 10, 2018
@francesca64 Please do, I have very little experience with the RandR protocol!
francesca64 commentedon May 10, 2018
@spearman this branch adds some debug messages: https://github.com/francesca64/winit/tree/x11-randr
@b-r-u
XRRGetScreenResourcesis apparently really slow, so I'm going to look into caching the monitor list and usingXRRSelectInputto receive events when the state changes. That's totally unrelated to this problem; I just enjoy caching things.spearman commentedon May 11, 2018
@francesca64 Compiling against the x11-randr branch actually detects 1 monitor and doesn't crash at all:
francesca64 commentedon May 11, 2018
Wait, really? All I did was refactor the monitor module. Well, I updated the branch to be ready for merging (besides the fact that I still need to impl
DebugforMonitorIdon all the other platforms) so if things still work after you pull that, I guess this is fixed.I plan on putting out a 0.14.1 release soon, which will include this.
(Since this was so quick, I'll save the caching for future work.)
spearman commentedon May 12, 2018
Hmm, yeah now it finds 0 monitors again and crashes on the call to get_primary_monitor
francesca64 commentedon May 12, 2018
The only way it could've changed is if it's somehow a timing issue that the
println!calls accidentally fixed, and since all the XRandR calls we make are synchronous, that shouldn't be possible.It seems like it only worked once as a fluke. If you want to check, you can step your way through the commits on that branch using an interactive rebase.
francesca64 commentedon May 12, 2018
...though, I guess that's specifically what
git bisectis for, but I've never used it.francesca64 commentedon May 12, 2018
I've pushed another commit which will print any X11 errors that occur, so if it's a protocol issue we'll find out quite easily.
spearman commentedon May 12, 2018
Well I don't see any X11 errors printing out, but this time it detects 1 monitor, but it's not the primary monitor, and crashes when trying to get primary (I added a debug print of the 1 available monitor):
francesca64 commentedon May 12, 2018
Ha, there's definitely something funky happening here. The thing is, if there's no primary monitor detected,
get_primary_monitorjust returns the first monitor in the list, andget_primary_monitorcallsget_available_monitorsinternally. This means you're getting inconsistent results between calls.francesca64 commentedon May 20, 2018
Is it consistently the second call that fails? Note that on master, the monitor list is now cached, so you'd want to disable that: https://github.com/tomaka/winit/blob/cebd15bfd1c5f9915fa5a97cfe0025bc462089e9/src/platform/linux/x11/monitor.rs#L19
Can you try capturing some logs for me using
xtrace(it's probably calledx11trace, depending on the package manager)?spearman commentedon May 20, 2018
Running with the current master for some reason it takes the xrandr 1.5 path, although the version is 1.4:
If I set FORCE_RANDR_COMPAT to true here's the output of xtrace:
https://gist.github.com/spearman/f5d443ae9186fa584cdb6f6a972d7081
francesca64 commentedon May 21, 2018
That's really weird. The condition should work the same as it did before: https://github.com/tomaka/winit/blob/v0.13.0/src/platform/linux/x11/monitor.rs#L28
I could just query the extension version instead of basing it on library availability, which is probably more correct anyway.
(and at bare minimum, an
assertthatmonitor_countisn't negative...)Anyway, I found the problem, and it's amusing. I pretty much never use iterators, so when I refactored, I didn't realize that calling
nextafter callingfindlike that would always result inNone(the previous code used two copies of the monitor list, so I'd removed one). This is much better than the conclusion that this is caused by some esoteric race condition.New branch: https://github.com/francesca64/winit/tree/x11-unregress-monitors
spearman commentedon May 21, 2018
Ok, now that one works, finds the primary monitor and no crashes =)