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

WidgetMatrix bug in all_widgets.rs #619

Closed
gkbrk opened this issue Nov 6, 2015 · 12 comments
Closed

WidgetMatrix bug in all_widgets.rs #619

gkbrk opened this issue Nov 6, 2015 · 12 comments
Labels

Comments

@gkbrk
Copy link

gkbrk commented Nov 6, 2015

When you click a box in the all_widgets.rs example, only the first block gets toggled. I presume the bug is because of this line here, when the closure runs it only changes the last value of col and row instead of the col and row when the closure was created.

@mitchmindtree
Copy link
Contributor

Hmmm I can't seem to be able to recreate this issue on my end?

That code snippet looks fine to me also - note that a Toggle is created for every element in the WidgetMatrix, and col and row are the column and row numbers for that element.

Sorry if I'm misunderstanding the issue!

@gkbrk
Copy link
Author

gkbrk commented Nov 7, 2015

I made a gif of what's happening:

Conrod Demo GIF

@bvssvni bvssvni added the bug label Nov 7, 2015
@waynenilsen
Copy link
Contributor

I'm able to recreate the issue. I can verify that it was not there as of my PR #586

@mitchmindtree
Copy link
Contributor

Thanks a lot for the gif! This is super strange! Even as of testing #623 I am still unable to recreate this issue. Perhaps there's some sort of cross-platform behavioural issue going on or something? I'm finding it difficult to imagine what it might be...

@bvssvni if you get a chance at all, could you test the latest version of conrod's all_widgets.rs example?

@gkbrk @waynenilsen what version of rustc and platform are you using?

I'm on osx 10.10.5, running rustc 1.4.0 (8ab8581f6 2015-10-27) using click press on my MBP's trackpad.

@gkbrk
Copy link
Author

gkbrk commented Nov 10, 2015

Linux Mint KDE, running rustc 1.4.0 (8ab8581f6 2015-10-27).

@waynenilsen
Copy link
Contributor

I'm on a vm running Ubuntu XFCE 15.4 inside of windows 10 running rust beta, don't have access to the machine so i can't say what exact version of rustc i'm running. I was clicking left click with the mouse

@xilec
Copy link

xilec commented Nov 10, 2015

I had got the same problem after updating to the last version. When I check it 5 days ago, it worked fine.

Windows 8.1
rustc 1.5.0-beta.2 (b0f440163 2015-10-28)
and
rustc 1.4.0 (8ab8581f6 2015-10-27)

Bug is reproduced only in debug version. In release version it works correctly.

@bvssvni
Copy link
Member

bvssvni commented Nov 10, 2015

I also get this bug on rustc 1.6.0-nightly (5b4986fa5 2015-11-08) OSX 10.9.5. Works in release mode.

@gkbrk
Copy link
Author

gkbrk commented Nov 10, 2015

I can confirm that it works when compiled on release mode.

@mitchmindtree
Copy link
Contributor

Oh wow, I've only been compiling in release mode so it makes sense that I've missed this. Confirmed it happens for me in debug also.

Anyone have any ideas why this might only occur in debug?

@mitchmindtree
Copy link
Contributor

Interestingly, if I add some printing to the Toggle's react closure, like so:

    // A demonstration using widget_matrix to easily draw
    // a matrix of any kind of widget.
    let (cols, rows) = (8, 8);
    WidgetMatrix::new(cols, rows)
        .down(20.0)
        .dimensions(260.0, 260.0) // matrix width and height.
        .each_widget(|n, col: usize, row: usize| { // called for every matrix elem.

            // Color effect for fun.
            let (r, g, b, a) = (
                0.5 + (col as f32 / cols as f32) / 2.0,
                0.75,
                1.0 - (row as f32 / rows as f32) / 2.0,
                1.0
            );

            // Now return the widget we want to set in each element position.
            // You can return any type that implements `Widget`.
            // The returned widget will automatically be positioned and sized to the matrix
            // element's rectangle.
            Toggle::new(demo.bool_matrix[col][row])
                .rgba(r, g, b, a)
                .frame(demo.frame_width)
                .react(|new_val: bool| {
                    println!("n: {:?}, col: {:?}, row: {:?}", n, col, row);
                    demo.bool_matrix[col][row] = new_val
                })
        })
        .set(TOGGLE_MATRIX, ui);

It prints a crazy number for n in debug when pressing random toggles:

n: 140734581765121, col: 0, row: 0
n: 140734581765121, col: 0, row: 0

However in release it behaves correctly:

n: 41, col: 5, row: 1
n: 0, col: 0, row: 0
n: 2, col: 0, row: 2

@mitchmindtree
Copy link
Contributor

Moving the matrix, col and row into Toggle's react closure seems to fix this:

    // A demonstration using widget_matrix to easily draw
    // a matrix of any kind of widget.
    let (cols, rows) = (8, 8);
    WidgetMatrix::new(cols, rows)
        .down(20.0)
        .dimensions(260.0, 260.0) // matrix width and height.
        .each_widget(|_n, col: usize, row: usize| { // called for every matrix elem.

            // Color effect for fun.
            let (r, g, b, a) = (
                0.5 + (col as f32 / cols as f32) / 2.0,
                0.75,
                1.0 - (row as f32 / rows as f32) / 2.0,
                1.0
            );

            // Now return the widget we want to set in each element position.
            // You can return any type that implements `Widget`.
            // The returned widget will automatically be positioned and sized to the matrix
            // element's rectangle.
            let val = demo.bool_matrix[col][row];
            let mat = &mut demo.bool_matrix;
            Toggle::new(val)
                .rgba(r, g, b, a)
                .frame(demo.frame_width)
                .react(move |new_val: bool| mat[col][row] = new_val)
        })
        .set(TOGGLE_MATRIX, ui);

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

No branches or pull requests

5 participants