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

Fix headless screenshot rendering (partially) #14

Merged
merged 7 commits into from
Feb 11, 2018
Merged

Fix headless screenshot rendering (partially) #14

merged 7 commits into from
Feb 11, 2018

Conversation

bwasty
Copy link
Owner

@bwasty bwasty commented Feb 5, 2018

Should solve #12.

Current state: Works fine on macOS, on Linux the resulting image is always black.

TODOs:

  • [ ] Fix Linux (black/transparent image - issue in glutin?) (postponed)
  • [ ] Test on Windows (postponed)
  • If not working on all platforms: add CLI switch to choose between 'real' headless and hidden window mode

@bwasty bwasty self-assigned this Feb 5, 2018
@bwasty bwasty mentioned this pull request Feb 5, 2018
Copy link

@siddhartpai siddhartpai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried pulling in this branch and taking a screenshot.
But i just ended up getting a black screen.

@bwasty
Copy link
Owner Author

bwasty commented Feb 6, 2018

Hmm - what OS? And do you mean 'screen' or the resulting PNG image?

@siddhartpai
Copy link

I'm using Arch Linux ,
On running the below command
./target/debug/gltf-viewer ./gltf/models/DamagedHelmet.gltf --screenshot a.png

a.png is just a black image.

@siddhartpai
Copy link

[ec2-user@ip-172-31-23-71 gltf-viewer]$ RUST_BACKTRACE=1 ./target/debug/gltf-viewer ./models/DamagedHelmet.gltf --screenshot a.png thread 'main' panicked at 'called Result::unwrap()on anErrvalue: NoBackendAvailable(LoadingError("LibraryNotFound { descr: \"libOSMesa.so: cannot open shared object file: No such file or directory\" }"))', /checkout/src/libcore/result.rs:906:4 stack backtrace: 0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49 1: std::sys_common::backtrace::_print at /checkout/src/libstd/sys_common/backtrace.rs:68 2: std::panicking::default_hook::{{closure}} at /checkout/src/libstd/sys_common/backtrace.rs:57 at /checkout/src/libstd/panicking.rs:381 3: std::panicking::default_hook at /checkout/src/libstd/panicking.rs:397 4: std::panicking::rust_panic_with_hook at /checkout/src/libstd/panicking.rs:577 5: std::panicking::begin_panic at /checkout/src/libstd/panicking.rs:538 6: std::panicking::begin_panic_fmt at /checkout/src/libstd/panicking.rs:522 7: rust_begin_unwind at /checkout/src/libstd/panicking.rs:498 8: core::panicking::panic_fmt at /checkout/src/libcore/panicking.rs:71 9: core::result::unwrap_failed at /checkout/src/libcore/macros.rs:23 10: <core::result::Result<T, E>>::unwrap at /checkout/src/libcore/result.rs:772 11: gltf_viewer::viewer::GltfViewer::new at src/viewer.rs:64 12: gltf_viewer::main at src/main.rs:87 13: __rust_maybe_catch_panic at /checkout/src/libpanic_unwind/lib.rs:101 14: std::rt::lang_start at /checkout/src/libstd/panicking.rs:459 at /checkout/src/libstd/panic.rs:365 at /checkout/src/libstd/rt.rs:58 15: main 16: __libc_start_main 17: <unknown>

This is what happens when i run it on an RHEL amazon aws instance which is where i'm trying to do headless rendering .

@bwasty
Copy link
Owner Author

bwasty commented Feb 6, 2018

I did some tests - on macOS everything works fine, on Ubuntu (16.04 Desktop) I first got the same error about libOSMesa.so. Fixed by installing libosmesa6-dev (apt-get - I don't know RHEL, but I guess there's an equivalent package).
But then I also just got black images. I tried increasing log level to max (-vvv) and adding another gl_check_error!() call after the screenshot, but it's no help. Not sure what else to try (perhaps open an issue for glutin?).

Alternative approach I've successfully used on a different project you might try to adapt to RHEL:

$ sudo apt-get install xvfb # depends on mesa, so it doesn't have to be installed explicitly
$ xvfb-run --auto-servernum --server-args="-screen 0 640x480x24" \
    cargo run -- Box.glb --screenshot b.png

This should work with the current 'faux' headless mode.

Perhaps I'll add a switch to choose between 'real' and 'faux' headless mode.

@siddhartpai
Copy link

I saw a similar issue opened on glutin,

rust-windowing/glutin#946

I can try the xfvb but i need this to work on an AWS Lambda; but Lambda doesn't have xfvb preinstalled . I'll see what i can do . Thank you for all your help.

@bwasty
Copy link
Owner Author

bwasty commented Feb 6, 2018

You definitely need mesa even if you can get around xvfb, so I'm not sure it can work on AWS Lambda if it's not already installed (found this related question).

@siddhartpai
Copy link

xvfb-run --auto-servernum --server-args="-screen 0 640x480x24" -e logs.log target/debug/gltf-viewer models/DamagedHelmet.gltf --screenshot a.png -w 640 -h 480
thread 'main' panicked at 'No backend is available', /home/ec2-user/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.10.1/src/platform/linux/mod.rs:340:8
note: Run with RUST_BACKTRACE=1 for a backtrace.

Even xvfb has issues with the faux headless mode . I'll give this a few more go's

@bwasty
Copy link
Owner Author

bwasty commented Feb 9, 2018

Today I had some time do to my own experiments on AWS (Ubuntu 16.04 instance) - I fixed the above error by installing xorg.

Then I started to put everything in Docker -> develop...headless_docker
Needs some cleanup still, but works - like this:
./screenshot_docker.sh ../gltf/glTF-Sample-Models/2.0/Box/glTF-Binary/Box.glb (only glb at the moment)

@bwasty bwasty changed the title Fix headless screenshot rendering WIP: Fix headless screenshot rendering Feb 9, 2018
@siddhartpai
Copy link

I'll have a look at this @bwasty. Thank you .

@bwasty
Copy link
Owner Author

bwasty commented Feb 10, 2018

Some notes from further experiments:

  • changed screenshot from RGB to RGBA - screenshots are still empty but now transparent instead of black
  • after explicitly specifying OpenGL version + profile (3.3), I now get an error that might help with further debugging:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: OsError("OSMesaCreateContextAttribs failed")', /checkout/src/libcore/result.rs:906:4
note: Run with `RUST_BACKTRACE=1` for a backtrace.

(from here)

Next step: generate more debug output with these queries: https://www.khronos.org/opengl/wiki/OpenGL_Context#Context_information_queries

@bwasty bwasty changed the title WIP: Fix headless screenshot rendering Fix headless screenshot rendering (partially) Feb 11, 2018
@bwasty
Copy link
Owner Author

bwasty commented Feb 11, 2018

I've decided to merge this as it is since I've made quite some progress on the docker branch.

@bwasty bwasty merged commit a8642f1 into develop Feb 11, 2018
@bwasty bwasty deleted the headless branch February 11, 2018 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants