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

Use-after-free crash if shader is dropped while program is in use #53

Open
Bash-09 opened this issue Sep 27, 2024 · 0 comments
Open

Use-after-free crash if shader is dropped while program is in use #53

Bash-09 opened this issue Sep 27, 2024 · 0 comments

Comments

@Bash-09
Copy link

Bash-09 commented Sep 27, 2024

The current triangle example code uses this to construct the shader program:

    let shader = shader::Library::from_bytes(SHADER_BYTES).unwrap();
    let vertex_shader = shader.get(0).unwrap();
    let program = shader::Program::new(vertex_shader).unwrap();

When changed to this:

    let program = {
        let shader = shader::Library::from_bytes(SHADER_BYTES).unwrap();
        let vertex_shader = shader.get(0).unwrap();
        shader::Program::new(vertex_shader).unwrap()
    };

shader is dropped which causes the internal *mut ctru_sys::DVLB_s to be freed. I believe this is required to stay alive while the Program is in use, I think its Entrypoint is used to bind uniforms and run the shader etc.

With the second version of the above code I was getting a crash due to a memory read error in libctru::DVLE_GetUniformRegister which had been called by citro3d::Shader::get_uniform.

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

1 participant