rust-windowing / glutin

A low-level library for OpenGL context creation, written in pure Rust.
Apache License 2.0
1.98k stars 474 forks source link

[Wayland] eglCreateContext failed #814

Closed genodeftest closed 5 years ago

genodeftest commented 7 years ago

When running servo under wayland, I'm getting this error message:

eglCreateContext failed: 0x3009 (thread main, at /home/username/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/servo-glutin-0.6.1/src/api/egl/mod.rs:726

stack backtrace:
   0:     0x55acfc33d7f1 - backtrace::backtrace::libunwind::trace
                        at /home/username/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.2.3/src/backtrace/mod.rs:82
                         - backtrace::backtrace::trace<closure>
                        at /home/username/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.2.3/src/backtrace/mod.rs:70
   1:     0x55acfc33e380 - backtrace::capture::{{impl}}::new
                        at /home/username/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.2.3/src/lib.rs:96
   2:     0x55acf80d4f1b - servo::main::{{closure}}
                        at /path/to/repository/of/servo/components/servo/main.rs:121
   3:     0x55acfcd58a55 - std::panicking::rust_panic_with_hook::hb1322e5f2588b4db
   4:     0x55acfcd58922 - std::panicking::begin_panic::hfbeda5aad583dc32
   5:     0x55acfcd58860 - std::panicking::begin_panic_fmt::h4fe9fb9d5109c4bf
   6:     0x55acf817df5e - glutin::api::egl::create_context
                        at /home/username/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/servo-glutin-0.6.1/src/api/egl/mod.rs:726
   7:     0x55acf817b4c2 - glutin::api::egl::{{impl}}::finish_impl
                        at /home/username/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/servo-glutin-0.6.1/src/api/egl/mod.rs:401
   8:     0x55acf817b00a - glutin::api::egl::{{impl}}::finish
                        at /home/username/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/servo-glutin-0.6.1/src/api/egl/mod.rs:374
   9:     0x55acf81a2156 - glutin::api::wayland::window::{{impl}}::new::{{closure}}
                        at /home/username/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/servo-glutin-0.6.1/src/api/wayland/window.rs:175
  10:     0x55acf814c23b - core::result::{{impl}}::and_then<glutin::api::egl::ContextPrototype,glutin::CreationError,glutin::api::egl::Context,closure>
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libcore/result.rs:601
  11:     0x55acf81899bc - glutin::api::wayland::window::{{impl}}::new
                        at /home/username/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/servo-glutin-0.6.1/src/api/wayland/window.rs:175
  12:     0x55acf819e506 - glutin::platform::platform::api_dispatch::{{impl}}::new
                        at /home/username/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/servo-glutin-0.6.1/src/platform/linux/api_dispatch.rs:188
  13:     0x55acf819eebc - glutin::window::{{impl}}::build
                        at /home/username/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/servo-glutin-0.6.1/src/window.rs:233
  14:     0x55acf811c9d1 - glutin_app::window::{{impl}}::new
                        at /path/to/repository/of/servo/ports/glutin/window.rs:169
  15:     0x55acf8122f25 - glutin_app::create_window
                        at /path/to/repository/of/servo/ports/glutin/lib.rs:48
  16:     0x55acf80ca060 - servo::main
                        at /path/to/repository/of/servo/components/servo/main.rs:138
  17:     0x55acfcd60cc6 - __rust_maybe_catch_panic
  18:     0x55acfcd57b61 - std::rt::lang_start::haaae1186de9de8cb
  19:     0x55acf80d5273 - main
  20:     0x7fc4e4c74730 - __libc_start_main
  21:     0x55acf7f83f78 - _start
  22:                0x0 - <unknown>
Servo exited with return value 101

From #577 I guess glutin doesn't support wayland yet. Any chance to force-fallback to X11?

elinorbgr commented 7 years ago

Basic glutin usage on wayland should work, unfortunately servo is not doing something like "basic" usage (see https://github.com/servo/servo/issues/9558 ).

You can try unsetting the WAYLAND_DISPLAY from your environment, this should prevent glutin from finding the wayland compositor, and making it fallback to X11.

genodeftest commented 7 years ago

hm, with unset WAYLAND_DISPLAY, servo runs into an unimplemented!() in glutin::api::wayland::window::{{impl}}::platform_display, so the same as you referenced in servo/servo#9958.

./mach run --dev
not yet implemented (thread main, at /home/username/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/servo-glutin-0.6.1/src/api/wayland/window.rs:324)
not yet implemented (thread PaintThread PipelineId { namespace_id: PipelineNamespaceId(0), index: PipelineIndex(0) }, at /home/username/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/servo-glutin-0.6.1/src/api/wayland/window.rs:26)
not yet implemented (thread Constellation, at /home/username/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/servo-glutin-0.6.1/src/api/wayland/window.rs:26)
stack backtrace:
   0:     0x561f533357f1 - backtrace::backtrace::libunwind::trace
                        at /home/username/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.2.3/src/backtrace/mod.rs:82
                         - backtrace::backtrace::trace<closure>
                        at /home/username/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.2.3/src/backtrace/mod.rs:70
   1:     0x561f53336380 - backtrace::capture::{{impl}}::new
                        at /home/username/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.2.3/src/lib.rs:96
   2:     0x561f4f0ccf1b - servo::main::{{closure}}
                        at /path/to/repository/of/servo/components/servo/main.rs:121
   3:     0x561f53d50a55 - std::panicking::rust_panic_with_hook::hb1322e5f2588b4db
   4:     0x561f4f0d7823 - std::panicking::begin_panic<&str>
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:383
   5:     0x561f4f10b14d - glutin::api::wayland::window::{{impl}}::platform_display
                        at /path/to/repository/of/servo/components/servo/<std macros>:3
   6:     0x561f4f10cbf1 - glutin::platform::platform::api_dispatch::{{impl}}::platform_display
                        at /home/username/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/servo-glutin-0.6.1/src/platform/linux/api_dispatch.rs:336
   7:     0x561f4f10b4fc - glutin::window::{{impl}}::platform_display
                        at /home/username/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/servo-glutin-0.6.1/src/window.rs:441
   8:     0x561f4f11965f - glutin_app::window::{{impl}}::native_display
                        at /path/to/repository/of/servo/ports/glutin/window.rs:834
   9:     0x561f4f0675f8 - compositing::compositor::{{impl}}::new<glutin_app::window::Window>
                        at /path/to/repository/of/servo/components/compositing/compositor.rs:460
  10:     0x561f4f06a5e9 - compositing::compositor::{{impl}}::create<glutin_app::window::Window>
                        at /path/to/repository/of/servo/components/compositing/compositor.rs:506
  11:     0x561f4efb79e7 - servo::{{impl}}::new<glutin_app::window::Window>
                        at /path/to/repository/of/servo/components/servo/lib.rs:192
  12:     0x561f4f0c2175 - servo::main
                        at /path/to/repository/of/servo/components/servo/main.rs:143
  13:     0x561f53d58cc6 - __rust_maybe_catch_panic
  14:     0x561f53d4fb61 - std::rt::lang_start::haaae1186de9de8cb
  15:     0x561f4f0cd273 - main
  16:     0x7f4fa2438730 - __libc_start_main
  17:     0x561f4ef7bf78 - _start
  18:                0x0 - <unknown>
Servo exited with return value 101
elinorbgr commented 7 years ago

This is troubling... What version of libwayland to you have? What wayland compositor do you use, and what is the value of WAYLAND_DISPLAY on your system?

genodeftest commented 7 years ago

What version of libwayland to you have?

libwayland-client-1.10.0-1.fc24.x86_64

What wayland compositor do you use

Gnome-shell 3.20

what is the value of WAYLAND_DISPLAY on your system?

WAYLAND_DISPLAY=wayland-0 by default. Not existing when I unset it.

I'll try in another wayland session and report back.

genodeftest commented 7 years ago

Even in a pure Weston session servo tries to use the wayland glutin API with unset WAYLAND_DISPLAY. So one of them (servo, glutin) has a different way to detect wayland or doesn't respect unsetting the environment variable.

elinorbgr commented 7 years ago

Oh, my bad, I thought libwayland had removed the default fallback on wayland-0, but they actually reverted it

So unsetting the environment variable won't prevent wayland to be used... So, to prevent glutin to use wayland, you'll need to patch it here : https://github.com/tomaka/glutin/blob/master/src/platform/linux/api_dispatch.rs#L37 replacing this line by if false for example.

Annnnd actually writing this, I realize the dispatch logic is broken, as it makes glutin use wayland as long as the wayland lib is here, even if no compositor is running, and I don't understand how it could have worked on my system when I pushed that code... I'll need to correct that.

The ideal would be to add an env variable allowing to force X11 for glutin... @tomaka are you still opposed to this? Something like GLUTIN_BACKEND, which can be set to wayland or x11 and if set to any of them glutin only tries this backend, rather than a fallback mechanism.

Now, outside of this hot-fix, what really bugs me is that the error is not the same depending on whether the WAYLAND_DISPLAY is set or not, while the only logic checking this env variable is in libwayland-client.so and it fallbacks to wayland-0 if the variable is not set, so both cases should be identical...

francesca64 commented 6 years ago

@vberger this issue is no longer relevant, correct?