Prevent crash when setting empty uniform array

The root of the problem is accessing the first element of an empty
array which reads out-of-bounds memory.
This commit is contained in:
Chris Thrasher 2024-07-31 11:00:41 -06:00
parent 779b963530
commit 2a4ca6e053

View File

@ -603,7 +603,7 @@ void Shader::setUniformArray(const std::string& name, const Glsl::Vec2* vectorAr
UniformBinder binder(*this, name);
if (binder.location != -1)
glCheck(GLEXT_glUniform2fv(binder.location, static_cast<GLsizei>(length), &contiguous[0]));
glCheck(GLEXT_glUniform2fv(binder.location, static_cast<GLsizei>(length), !contiguous.empty() ? &contiguous[0] : NULL));
}
@ -614,7 +614,7 @@ void Shader::setUniformArray(const std::string& name, const Glsl::Vec3* vectorAr
UniformBinder binder(*this, name);
if (binder.location != -1)
glCheck(GLEXT_glUniform3fv(binder.location, static_cast<GLsizei>(length), &contiguous[0]));
glCheck(GLEXT_glUniform3fv(binder.location, static_cast<GLsizei>(length), !contiguous.empty() ? &contiguous[0] : NULL));
}
@ -625,7 +625,7 @@ void Shader::setUniformArray(const std::string& name, const Glsl::Vec4* vectorAr
UniformBinder binder(*this, name);
if (binder.location != -1)
glCheck(GLEXT_glUniform4fv(binder.location, static_cast<GLsizei>(length), &contiguous[0]));
glCheck(GLEXT_glUniform4fv(binder.location, static_cast<GLsizei>(length), !contiguous.empty() ? &contiguous[0] : NULL));
}
@ -640,7 +640,7 @@ void Shader::setUniformArray(const std::string& name, const Glsl::Mat3* matrixAr
UniformBinder binder(*this, name);
if (binder.location != -1)
glCheck(GLEXT_glUniformMatrix3fv(binder.location, static_cast<GLsizei>(length), GL_FALSE, &contiguous[0]));
glCheck(GLEXT_glUniformMatrix3fv(binder.location, static_cast<GLsizei>(length), GL_FALSE, !contiguous.empty() ? &contiguous[0] : NULL));
}
@ -655,7 +655,7 @@ void Shader::setUniformArray(const std::string& name, const Glsl::Mat4* matrixAr
UniformBinder binder(*this, name);
if (binder.location != -1)
glCheck(GLEXT_glUniformMatrix4fv(binder.location, static_cast<GLsizei>(length), GL_FALSE, &contiguous[0]));
glCheck(GLEXT_glUniformMatrix4fv(binder.location, static_cast<GLsizei>(length), GL_FALSE, !contiguous.empty() ? &contiguous[0] : NULL));
}