Skip to content

Commit

Permalink
Remove trivial and unnecessary UB
Browse files Browse the repository at this point in the history
I don't understand why it was written this way. [glGenTextures](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glGenTextures.xhtml) is passed a mutable pointer which is set as an out parameter, but the existing code was transmuting a shared reference to the buffer to a mutable pointer, which is undefined behavior. The fix is trivial: just make the buffer mutable and pass a mutable reference instead.
  • Loading branch information
digama0 committed Apr 15, 2022
1 parent 4634642 commit ebdc18e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/texture/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ pub fn new_texture<'a, F: ?Sized, P>(facade: &F, format: TextureFormatRequest,

BufferAny::unbind_pixel_unpack(&mut ctxt);

let id: gl::types::GLuint = 0;
ctxt.gl.GenTextures(1, mem::transmute(&id));
let mut id: gl::types::GLuint = 0;
ctxt.gl.GenTextures(1, &mut id);

{
ctxt.gl.BindTexture(bind_point, id);
Expand Down

0 comments on commit ebdc18e

Please sign in to comment.