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

Set_Speed = "Instant" produces incorrect output #234

Open
bharathk005 opened this issue Mar 14, 2021 · 10 comments
Open

Set_Speed = "Instant" produces incorrect output #234

bharathk005 opened this issue Mar 14, 2021 · 10 comments
Labels

Comments

@bharathk005
Copy link
Contributor

While setting the turtle speed to "instant" I am seeing issues with the fill color.
Tried with
turtle.set_speed(Speed::instant());
turtle.set_speed("instant");

image

@sunjay
Copy link
Owner

sunjay commented Mar 14, 2021

Could you tell me which Rust version (rustc --version --verbose) and operating system you are on? Please also provide your Cargo.lock file and tell me the exact command you ran to reproduce this.

This is definitely odd because setting the speed has nothing to do with how fills are calculated. It just affects how quickly the points are recorded. Does this still happen if the speed is very high (e.g. at 25)?

@bharathk005
Copy link
Contributor Author

bharathk005 commented Mar 15, 2021

@sunjay
rustc 1.50.0 (cb75ad5db 2021-02-10)
windows
cargo run --example rust (from the root directory)
Attaching Cargo.lock

@bharathk005
Copy link
Contributor Author

Cargo.lock.txt

@sunjay sunjay added the bug label Mar 16, 2021
@bharathk005
Copy link
Contributor Author

bharathk005 commented Mar 17, 2021

@sunjay
I missed mentioning that setting the speed to 25 does not reproduce the issue. Occurs only when speed is set to "instant".

@sunjay
Copy link
Owner

sunjay commented Mar 17, 2021

Another thing I'd be curious to test is if it still happens if you set the IPC channel crate version to 0.14. We recently updated in #235 and this could happen if that crate is sending messages in the wrong order. (Sending messages in the wrong order shouldn't technically be possible because we always wait for a drawing to finish before sending the next one, but it's worth testing anyway just in case.)

@bharathk005
Copy link
Contributor Author

IPC channel is already in 0.14. I think #235 was merged 2 days ago. I never pulled from upstream after that.

@sunjay
Copy link
Owner

sunjay commented Mar 17, 2021

Ah okay. We can rule that out then. For anyone looking to work on this: I suggest printing out the messages being sent to the renderer process and making sure they are the same regardless of the speed. I also suggest printing out the display list and comparing at different speeds. Note that you don't need to run the entire example to debug this, just up to a portion of the drawing that appears different at different speeds.

@bharathk005
Copy link
Contributor Author

I put some print messages in rust example also in the send method of ipc_protocol
Could see that setting "instant" and 25 produces the same output.

image

image

@sunjay
Copy link
Owner

sunjay commented Mar 17, 2021

Right. That's good. Then the next place I'd look is whether the display lists are the same.

@sathwikmatsa
Copy link
Contributor

The issue arises from the way MoveAnimation deals with Instant speed. More precisely, on line 126 below:

if cfg!(any(feature = "test", test)) || speed.is_instant() {
// Set to the final position and draw a line with no animation
turtle.state.position = target_pos;
let prim = display_list.push_line(position, target_pos, pen);
turtle.drawings.extend(prim);
// Append to the current fill polygon, if any
let fill_poly_index = turtle.current_fill_polygon.map(|poly_handle| {
display_list.polygon_push(poly_handle, position)
});

we update fill polygon with old position (or current position before animation) instead of new or target position.

sample code to reproduce:

use turtle::Turtle;

fn main() {
    let mut turtle = Turtle::new();
    turtle.set_speed(x);

    turtle.begin_fill();
    for _ in 0..2 {
        turtle.forward(200.0);
        turtle.right(90.0);
    }
    turtle.end_fill();
}
x is not instant x is instant
Screenshot from 2021-07-17 11-26-22 Screenshot from 2021-07-17 11-23-09

display_list.polygon_push(poly_handle, target_pos) will fix the issue.

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

3 participants