FIX:Add array out of bounds protection

jira: none
Change-Id: I038e45be00664ab35dfbc2d59ddfa6c018cd2873
(cherry picked from commit d4967c8c269d0f9b918e9049addcd7d6f6fd2656)
This commit is contained in:
zhou.xu 2025-08-12 17:19:41 +08:00 committed by Noisyfox
parent 1c793a5ad1
commit ef5458d231

View file

@ -3467,17 +3467,20 @@ m_no_render_path = false;
offset += static_cast<unsigned int>(sub_path.first.i_id);
// gets the vertex index from the index buffer on gpu
const IBuffer& i_buffer = buffer.indices[sub_path.first.b_id];
unsigned int index = 0;
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, i_buffer.ibo));
glsafe(::glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, static_cast<GLintptr>(offset * sizeof(IBufferType)), static_cast<GLsizeiptr>(sizeof(IBufferType)), static_cast<void*>(&index)));
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
// gets the position from the vertices buffer on gpu
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, i_buffer.vbo));
glsafe(::glGetBufferSubData(GL_ARRAY_BUFFER, static_cast<GLintptr>(index * buffer.vertices.vertex_size_bytes()), static_cast<GLsizeiptr>(3 * sizeof(float)), static_cast<void*>(sequential_view->current_position.data())));
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
if (sub_path.first.b_id >= 0 && sub_path.first.b_id < buffer.indices.size()) {
const IBuffer &i_buffer = buffer.indices[sub_path.first.b_id];
unsigned int index = 0;
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, i_buffer.ibo));
glsafe(::glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, static_cast<GLintptr>(offset * sizeof(IBufferType)),
static_cast<GLsizeiptr>(sizeof(IBufferType)), static_cast<void *>(&index)));
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
// gets the position from the vertices buffer on gpu
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, i_buffer.vbo));
glsafe(::glGetBufferSubData(GL_ARRAY_BUFFER, static_cast<GLintptr>(index * buffer.vertices.vertex_size_bytes()),
static_cast<GLsizeiptr>(3 * sizeof(float)), static_cast<void *>(sequential_view->current_position.data())));
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
}
sequential_view->current_offset = Vec3f::Zero();
found = true;
break;