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

Rendering bug after a new Texture2D is loaded #17

Closed
liamzdenek opened this issue Mar 14, 2016 · 3 comments
Closed

Rendering bug after a new Texture2D is loaded #17

liamzdenek opened this issue Mar 14, 2016 · 3 comments

Comments

@liamzdenek
Copy link

Loading an image within a program's main loop will cause visual artifacts to appear in the elements rendered by ImGui. Here is an example using a 256x256 image:

Here is the isolated test case:

#[macro_use]
extern crate glium;
#[macro_use]
extern crate imgui;
extern crate image;


use glium::glutin;
use glium::{DisplayBuild, Surface};
use imgui::ImGui;
use imgui::glium_renderer::Renderer;

use std::io::Cursor;

fn main() {
    let mut count = 0;

    let display = glutin::WindowBuilder::new()
        .build_glium()
        .unwrap();

    let mut imgui = ImGui::init();

    let mut renderer = Renderer::init(&mut imgui, &display).unwrap();

    let mut open = true;
    loop {
        count += 1;

        // make sure it renders properly for the first few frames
        if count > 200 {
           let img_bkup = {
                let image = image::load(Cursor::new(&include_bytes!("test.png")[..]), image::PNG).unwrap().to_rgba();
                let image_dimensions = image.dimensions(); 
                let image = glium::texture::RawImage2d::from_raw_rgba_reversed(image.into_raw(), image_dimensions);
                glium::texture::Texture2d::new(&display, image).unwrap()
           }; 
        }

        let mut target = display.draw();
        target.clear_color(0.2, 0.2, 0.2, 1.0);

        let (width, height) = target.get_dimensions();
        let ui = imgui.frame(width, height, 0.0);

        {
            ui.show_test_window(&mut open);
        }

        renderer.render(&mut target, ui).unwrap();
        target.finish().unwrap();
    }
}

using versions:

imgui = "0.0.7-pre" // also reproducible with 0.0.6 from crates.io
image = "0.0.7"
glium = "0.13"

This line causes the problem: glium::texture::Texture2d::new(&display, image).unwrap()

I've tested images of 256x256 and 512x512 and it is reproducible with all of them.

I suspect that the texture used by ImGui was accidentally freed, and this image is overwriting it -- but I'm not exactly sure. I don't know of a workaround at this point other than to frontload all textures, or reinitialize ImGui at runtime, both of which are less than ideal.

Any insight would be greatly appreciated!

@Gekkio
Copy link
Contributor

Gekkio commented Mar 14, 2016

Hmm, I think I've seen this too at some point. No clue about why it happens 😢
I trust Glium, so it's probably something in the unsafe parts of core imgui-rs, the glium renderer, or the shaders.
I'll look into it when I have some time.

@brendanzab
Copy link
Contributor

I'm having this issue too. For me, it's after I render some text to a texture.

@Gekkio
Copy link
Contributor

Gekkio commented Mar 26, 2016

Oh boy, this was tough to debug. Due to a simple naming error, the font atlas texture was never bound before use, but if no other textures were used, the atlas texture stayed as the "current texture" after creation and everything worked by accident.

@Gekkio Gekkio closed this as completed in 550b8d1 Mar 26, 2016
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