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

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

Open
JaniM opened this issue Jan 5, 2025 · 4 comments

Comments

@JaniM
Copy link

JaniM commented Jan 5, 2025

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
Copy link
Author

JaniM commented Jan 6, 2025

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);

@not-fl3
Copy link
Owner

not-fl3 commented Jan 6, 2025

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

@historydev
Copy link

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.

@JaniM
Copy link
Author

JaniM commented Jan 7, 2025

It is fixed on master.

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

No branches or pull requests

3 participants