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

Examples Don't Run #717

Closed
Bluebird45 opened this issue Apr 30, 2016 · 15 comments
Closed

Examples Don't Run #717

Bluebird45 opened this issue Apr 30, 2016 · 15 comments

Comments

@Bluebird45
Copy link
Contributor

This on Linux x64, Rust 1.8, Rustup, for all the examples, although "cargo test" passes OK:

$ cargo run --example all_widgets
Running target/debug/examples/all_widgets
thread '

' panicked at 'Failed to get root window: XError { description: "GLXBadFBConfig", error_code: 178, request_code: 155, minor_code: 34 }', ../src/libcore/result.rs:746
note: Run with RUST_BACKTRACE=1 for a backtrace.
Process didn't exit successfully: target/debug/examples/all_widgets (exit code: 101)

@bvssvni
Copy link
Member

bvssvni commented Apr 30, 2016

You could try switching the window backend:

extern crate sdl2_window;

use sdl2_window::Sd2lWindow;

let window = PistonWindow<Sdl2Window> = ...;

piston_window uses pistoncore-glutin_window by default, but you can change to another, for example pistoncore-sdl2_window if there are problems on your platform.

@Bluebird45
Copy link
Contributor Author

Bluebird45 commented May 1, 2016

OK, I installed sdl2, and then edited all_widgets.rs as you suggest above, as well as Cargo.toml to add that dependency. I also downgraded the line in examples/custom_widget.rs that mentions the OpenGL version, from 3_2 to 2_1 (which actually is the version of OpenGL according to glxinfo) since that is the tactic that worked to get the spinning square running. That is the only source code file in the package that refers to the OpenGL version.

I also changed computers: both are Dells with onboard graphics controller. I made sure I had the latest available drivers installed from Debian's testing repo.

"cargo test" passes

but running the example fails:

$ cargo run --release --example all_widgets
Running `target/release/examples/all_widgets` thread '' panicked at
'called `Result::unwrap()` on an `Err` value: "Could not create GL context"',
../src/libcore/result.rs:746 note: Run with `RUST_BACKTRACE=1` for a backtrace.
Process didn't exit successfully: `target/release/examples/all_widgets` (exit code: 101)

Any ideas?

@Bluebird45
Copy link
Contributor Author

Bluebird45 commented May 1, 2016

Here is the same (SDL2) build running backtrace:

$ RUST_BACKTRACE=1 cargo run --release --example all_widgets
Running `target/release/examples/all_widgets` thread '' panicked at 'called
`Result::unwrap()` on an `Err` value: "Could not create GL context"',
../src/libcore/result.rs:746 stack backtrace:
   1:     0x7fc1e3f96c00 - sys::backtrace::tracing::imp::write::h3675b4f0ca767761Xcv
   2:     0x7fc1e3f9938b - panicking::default_handler::_$u7b$$u7b$closure$u7d$$u7d$::closure.44519
   3:     0x7fc1e3f98ff8 - panicking::default_handler::h18faf4fbd296d909lSz
   4:     0x7fc1e3f8ddcc - sys_common::unwind::begin_unwind_inner::hfb5d07d6e405c6bbg1t
   5:     0x7fc1e3f8e258 - sys_common::unwind::begin_unwind_fmt::h8b491a76ae84af35m0t
   6:     0x7fc1e3f961b1 - rust_begin_unwind
   7:     0x7fc1e3fc880f - panicking::panic_fmt::h98b8cbb286f5298alcM
   8:     0x7fc1e3e7e3de - result::unwrap_failed::h1052714907860631344
   9:     0x7fc1e3e7bc84 - main::h1d3daaf722cf6b26Jea
  10:     0x7fc1e3f98c54 - sys_common::unwind::try::try_fn::h14622312129452522850
  11:     0x7fc1e3f9613b - __rust_try
  12:     0x7fc1e3f986eb - rt::lang_start::h0ba42f7a8c46a626rKz
  13:     0x7fc1e2f77b44 - __libc_start_main
  14:     0x7fc1e3e728e8 - 
  15:                0x0 - 
Process didn't exit successfully: `target/release/examples/all_widgets` (exit code: 101)

In the above backtrace, I don't know of a way to determine the point in the source code where the "unwrap failed" line occurs, although it seems likely to be the first occurrence of unwrap, which is where I made one of the changes that you suggested:

fn main() {
    // Construct the window.
    let mut window: PistonWindow<(), Sdl2Window> =
        WindowSettings::new("All The Widgets!", [1100, 560])
            .exit_on_esc(true).vsync(true).build().unwrap();

@Bluebird45
Copy link
Contributor Author

Bluebird45 commented May 1, 2016

Same result when I similarly modify and then run another, much simpler example:

$ cargo run --release --example image
Running `target/release/examples/image` thread '' panicked at
'called `Result::unwrap()` on an `Err` value: "Could not create GL context"',
../src/libcore/result.rs:746 note: Run with `RUST_BACKTRACE=1` for a backtrace.
Process didn't exit successfully: `target/release/examples/image` (exit code: 101)

@Bluebird45
Copy link
Contributor Author

Bluebird45 commented May 1, 2016

Every example fails with the same error.

Please look over the source of the modified counter.rs and tell me if I'm doing anything wrong. Changes to the original code are indicated:

#[macro_use] extern crate conrod;
extern crate find_folder;
extern crate piston_window;
extern crate sdl2_window;        //CHANGED HERE     
fn main() {
    use conrod::{Labelable, Positionable, Sizeable, Theme, Widget};
    use piston_window::{EventLoop, Glyphs, PistonWindow, UpdateEvent, WindowSettings};
    use sdl2_window::Sdl2Window;        //CHANGED HERE
    // Conrod is backend agnostic. Here, we define the `piston_window` backend to use for our `Ui`.
    type Backend = ( as conrod::Graphics>::Texture, Glyphs);
    type Ui = conrod::Ui;
    // Construct the window.
//CHANGED THE FOLLOWING LINE
    let mut window: PistonWindow<(), Sdl2Window> = WindowSettings::new("Click me!", [200, 200])
        .exit_on_esc(true).build().unwrap();
    // construct our `Ui`.
    let mut ui = {
        let assets = find_folder::Search::KidsThenParents(3, 5)
            .for_folder("assets").unwrap();
        let font_path = assets.join("fonts/NotoSans/NotoSans-Regular.ttf");
        let theme = Theme::default();
        let glyph_cache = Glyphs::new(&font_path, window.factory.clone());
        Ui::new(glyph_cache.unwrap(), theme)
    };
    let mut count = 0;
    window.set_ups(60);
    // Poll events from the window.
    while let Some(event) = window.next() {
        ui.handle_event(&event);
        event.update(|_| ui.set_widgets(|ref mut ui| {
            // Generate the ID for the Button COUNTER.
            widget_ids!(CANVAS, COUNTER);
            // Create a background canvas upon which we'll place the button.
            conrod::Canvas::new().pad(40.0).set(CANVAS, ui);
            // Draw the button and increment `count` if pressed.
            conrod::Button::new()
                .middle_of(CANVAS)
                .w_h(80.0, 80.0)
                .label(&count.to_string())
                .react(|| count += 1)
                .set(COUNTER, ui);
        }));
        window.draw_2d(&event, |c, g| ui.draw_if_changed(c, g));
    }
}

@bvssvni
Copy link
Member

bvssvni commented May 1, 2016

The code looks right, except it should be let mut window: PistonWindow<Sdl2Window> (only one generic argument).

@bvssvni
Copy link
Member

bvssvni commented May 1, 2016

Does the "user_input" example work for you? You can change the window backend in the Cargo.toml:

include_sdl2 => include_glutin

@bvssvni
Copy link
Member

bvssvni commented May 1, 2016

@Bluebird45
Copy link
Contributor Author

Bluebird45 commented May 1, 2016

The user_input example and all the other piston-example binaries performed perfectly after I specified OpenGL 2_1 in their source. Without that they fail to run, as expected, with an error message of "Could not create GL context".

I then changed the window backend of user_input to glutin as you suggest and that worked perfectly too.

Side note 1: That method could be a handy option in the other examples as well.

Side note 2: texture_swap.rs needs amending to include the .opengl(opengl) parameter, otherwise the preceding "let opengl" binding generates (on any platform) a warning about it being unused, and on OpenGL 2_1 systems such as mine will fail to run.

    let opengl = OpenGL::V2_1;

    let mut window: PistonWindow = WindowSettings::new("piston", [1024; 2]).opengl(opengl).build().unwrap();
                                                                            ^^^^^^^^^^^^^^

Thank you for your help!

I'll see if I can apply those lessons to the Conrod examples and I'll post an update here, whether I succeed or not.

@Bluebird45
Copy link
Contributor Author

Bluebird45 commented May 2, 2016

I'm still not there getting Conrod to work. Here's the problem, as I understand it (but correct me if it is incorrect):

Both SDL2 and Glutin expect OpenGL 3 unless told otherwise.

Piston_examples uses SDL2 by default, and Conrod uses Glutin.

SDL2 has built-in pointers to OpenGL aliases, so downgrading a program's OpenGL calls to version 2_1 is simply a matter of specifying it in the command that creates a new window, with the parameter: .opengl(OpenGL::V2_1) That's one variation, at least.

Glutin does not have OpenGL pointers built-in, but they must be added with one or more extra crates/libraries. I still have not found a combination of these that actually allows the Conrod examples to compile. Quite possibly my beginner's grasp of the way Rust compiles is at fault here.

How do I add such malleability of the OpenGL version to Glutin?

@bvssvni
Copy link
Member

bvssvni commented May 2, 2016

The Conrod examples use Gfx. The window backends initializes a global OpenGL context.

It could be something with the OpenGL 2.1 context not allowed to be initialized twice. Just guessing.

@Bluebird45
Copy link
Contributor Author

Well, gfx isn't in the toml file as a dependency. I suppose that's because it is fetched by something else that is in the toml file. But how is one to know, without being a piston developer thoroughly conversant with the project?

Is there some guide somewhere to explain how the graphics components fit together?

@bvssvni
Copy link
Member

bvssvni commented May 2, 2016

There is the overview.

piston_window uses Gfx.

@Bluebird45
Copy link
Contributor Author

Piston_examples runs for me, when I change the OpenGL parameter for a new window to 2_1.

Piston_examples uses piston_window to create a new window.

Conrod lists piston_window as a dev dependency in its toml file.

Does this mean that Conrod uses piston_window to create a new window?

If so, why can I not edit the Conrod examples source the same way that I edited the piston_examples source, namely by passing a parameter that specifies OpenGL version 2.1? When I try to do that the compile crashes with an error of unresolved variable.

@Bluebird45
Copy link
Contributor Author

Bluebird45 commented May 3, 2016

I finally got it working, with all_widgets working perfectly.

I had to make two changes to each example:

  1. Add OpenGL to the "use piston_window" declaration:

Like this, for example:

use piston_window::{EventLoop, Glyphs, OpenGL, PistonWindow, UpdateEvent, WindowSettings};
//                                     ^^^^^^^
  1. Add the OpenGL version to the new window command:

Like this, for example:

// Construct the window.
let mut window: PistonWindow =
    WindowSettings::new("All The Widgets!", [1100, 560])
        .exit_on_esc(true).vsync(true).opengl(OpenGL::V2_1).build().unwrap();
//                                    ^^^^^^^^^^^^^^^^^^^^^

These values should be coded in, at least for 3_2, to make modification easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants