Skip to content

Scrissor rect should be clamped #1447

@andraantariksa

Description

@andraantariksa

I was following this example, but I always encounter an error about invalid scissor. I just found out the problem was the rect was overflowing the surface bound. I guess the example need to be updated so no one will stumble upon my same exact problem.

https://github.com/PistonDevelopers/conrod/blob/master/backends/conrod_wgpu/examples/all_winit_wgpu.rs#L247

more or less, it can be rewritten into

conrod_wgpu::RenderPassCommand::SetScissor {
    top_left: [x, y],
    dimensions: [w, h],
} => {
    render_pass.set_scissor_rect(x, y, w, h);
}

It should be clamped to the surface size

conrod_wgpu::RenderPassCommand::SetScissor {
    top_left: [x, y],
    dimensions: [mut w, mut h],
} => {
    if w + x > surface_config.surface.width { // Surface width
        w = surface_config.surface.width - x;
    }
    if h + y > surface_config.surface.height { // Surface height
        h = surface_config.surface.height - y;
    }
    render_pass.set_scissor_rect(x, y, w, h);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions