macroquad icon indicating copy to clipboard operation
macroquad copied to clipboard

Drawing to the second render target created on the same frame results in a white texture

Open JaniM opened this issue 11 months ago • 5 comments

Full reproduction below. If you remove the marked line, the code works as expected.

use macroquad::prelude::*;

const VIRTUAL_WIDTH: f32 = 1280.0;
const VIRTUAL_HEIGHT: f32 = 720.0;

#[macroquad::main("Letterbox")]
async fn main() {

    // remove the following line and it works
    render_target(VIRTUAL_WIDTH as u32, VIRTUAL_HEIGHT as u32); // <--

    let render_target = render_target(VIRTUAL_WIDTH as u32, VIRTUAL_HEIGHT as u32);

    let mut render_target_cam =
        Camera2D::from_display_rect(Rect::new(0., 0., VIRTUAL_WIDTH, VIRTUAL_HEIGHT));
    render_target_cam.render_target = Some(render_target.clone());

    loop {
        set_camera(&render_target_cam);
        clear_background(BLUE);
        draw_circle(VIRTUAL_WIDTH / 2.0 - 65.0, VIRTUAL_HEIGHT / 2.0, 35.0, RED);

        set_default_camera();
        clear_background(BLACK);
        draw_texture_ex(
            &render_target.texture,
            0.,
            0.,
            WHITE,
            DrawTextureParams {
                ..Default::default()
            },
        );

        next_frame().await;
    }
}

JaniM avatar Jan 05 '25 21:01 JaniM

Triage:

  • This is related to the drop handler of textures. The following code does not exhibit the error.
let _foo = render_target(VIRTUAL_WIDTH as u32, VIRTUAL_HEIGHT as u32);
let render_target = render_target(VIRTUAL_WIDTH as u32, VIRTUAL_HEIGHT as u32);
  • If I delete these three lines, the bug is not exhibited. https://github.com/not-fl3/macroquad/blob/2f7f3c8433bbec3bc8829b231db0e19a6f2b5432/src/texture.rs#L56-L58

  • If I delete this line in miniquad, the issue doesn't happen. https://github.com/not-fl3/miniquad/blob/ca8d6341690085aa01924db6c8e03989d9c262f7/src/graphics/gl.rs#L857

  • The issue does not exist on the current master version of macroquad.

JaniM avatar Jan 06 '25 14:01 JaniM

I believe it was fixed already but it did not yet made to crates.io

not-fl3 avatar Jan 06 '25 23:01 not-fl3

I believe it was fixed already but it did not yet made to crates.io

let rt1 = render_target(VIRTUAL_WIDTH as u32, VIRTUAL_HEIGHT as u32); // <-- works
let _ = render_target(VIRTUAL_WIDTH as u32, VIRTUAL_HEIGHT as u32); // <-- white screen /* == */ 
render_target(VIRTUAL_WIDTH as u32, VIRTUAL_HEIGHT as u32); // <-- white screen

It seems that if the return value is not used, what the author sees is what you get.

historydev avatar Jan 07 '25 21:01 historydev

It is fixed on master.

JaniM avatar Jan 07 '25 21:01 JaniM

For me it went away after updating

lucyamonster avatar Apr 02 '25 14:04 lucyamonster