Skip to content

A Rendering bug when resizing #1027

@mewadahimansh01-stack

Description

@mewadahimansh01-stack

Description

I am making a pong clone and this bug came to light. In the given game when I click on maximize then maximize again to go back to normal size, the right paddle disappears completely and doesn't reappear until i resize it by dragging the borders, then it stays even if you click on maximize repeatedly. I believe my code should work normally for the first resize. What are your views on it ? The code is provided below, if anyone wants to check you can remove the logo parts and it should still produce the same bug.

My Computer Specifications are:

Operating System: Arch Linux
KDE Plasma Version: 6.6.2
KDE Frameworks Version: 6.23.0
Qt Version: 6.10.2
Kernel Version: 6.19.8-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 4 × Intel® Core™ i7-6600U CPU @ 2.60GHz
Memory: 8 GiB of RAM (7.6 GiB usable)
Graphics Processor 1: Intel® HD Graphics 520
Graphics Processor 2: AMD Radeon R7 M360
Manufacturer: Dell Inc.
Product Name: Latitude E5470

Code

use macroquad::{miniquad::conf::Icon, prelude::*};

#[macroquad::main(window_conf)]
async fn main() {

    let width = screen_width();
    let height = screen_height();

    let paddle = [width / 40., height/ 5.];
    let mut position_left = [
        width / 2. - 2. * width / 5. - paddle[0] / 2.,
        height / 2. - height / 6.,
    ];
    let mut position_right = [
        width / 2. + 2. * width / 5. - paddle[0] / 2.,
        height / 2. - height / 6.,
    ];

    loop {

        if width != screen_width() || height != screen_height() {
            position_left = [
                screen_width() / 2. - 2. * screen_width() / 5. - paddle[0] / 2.,
                screen_height() / 2. - screen_height() / 6.,
            ];
            position_right = [
                screen_width() / 2. + 2. * screen_width() / 5. - paddle[0] / 2.,
                screen_height() / 2. - screen_height() / 6.,
            ];
        }

        clear_background(BEIGE);

        // x, y, w, h, color
        // right paddle
        draw_rectangle(
            position_right[0],
            position_right[1],
            paddle[0],
            paddle[1],
            RED,
        );

        // left paddle
        draw_rectangle(
            position_left[0],
            position_left[1],
            paddle[0],
            paddle[1],
            RED,
        );

        next_frame().await;
    }
}

fn window_conf() -> Conf {
    Conf {
        window_resizable: true,
        window_title: "Pong Clone".to_string(),
        icon: Some(set_window_icon()),
        ..Default::default()
    }
}

fn set_window_icon() -> Icon {
    Icon {
        small: *include_bytes!("logo16.rgba"),
        medium: *include_bytes!("logo32.rgba"),
        big: *include_bytes!("logo64.rgba"),
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions