Skip to content

Commit

Permalink
fix(iv): avoid crash with OpenGL + multi-channel images (#4087)
Browse files Browse the repository at this point in the history
For image with more than 4 channels, we were misallocating the OpenGL
buffer by using the total channels instead of the 4 we wanted to create
the texture out of. Also, make sure the calculation usees wide types to
avoid possible integer overflow.

Signed-off-by: Larry Gritz <[email protected]>
  • Loading branch information
lgritz authored Dec 27, 2023
1 parent 6ed14ff commit a9c937d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/iv/ivgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,10 @@ IvGL::load_texture(int x, int y, int width, int height)
}

glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_pbo_objects[m_last_pbo_used]);
glBufferData(GL_PIXEL_UNPACK_BUFFER, width * height * spec.pixel_bytes(),
glBufferData(GL_PIXEL_UNPACK_BUFFER,
GLsizeiptr(uint64_t(width) * uint64_t(height)
* uint64_t(nchannels)
* uint64_t(spec.format.size())),
&m_tex_buffer[0], GL_STREAM_DRAW);
print_error("After buffer data");
m_last_pbo_used = (m_last_pbo_used + 1) & 1;
Expand Down

0 comments on commit a9c937d

Please sign in to comment.