From 03c159202221d48482718f3027ae855d7768e78d Mon Sep 17 00:00:00 2001 From: heinezen Date: Sun, 6 Oct 2024 00:34:23 +0200 Subject: [PATCH] renderer: Fix tex unit assignment for std::optional type. --- libopenage/renderer/opengl/shader_program.cpp | 7 +++++-- libopenage/renderer/opengl/shader_program.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libopenage/renderer/opengl/shader_program.cpp b/libopenage/renderer/opengl/shader_program.cpp index 395ee395c2..4b46a8263c 100644 --- a/libopenage/renderer/opengl/shader_program.cpp +++ b/libopenage/renderer/opengl/shader_program.cpp @@ -424,8 +424,11 @@ void GlShaderProgram::update_uniforms(std::shared_ptr const &uni glBindTexture(GL_TEXTURE_2D, tex); // TODO: maybe call this at a more appropriate position glUniform1i(loc, tex_unit_id); - auto &tex_value = *this->textures_per_texunits[tex_unit_id]; - tex_value = tex; + ENSURE(tex_unit_id < this->textures_per_texunits.size(), + "Tried to assign texture to non-existant texture unit at index " + << tex_unit_id + << " (max: " << this->textures_per_texunits.size() << ")."); + this->textures_per_texunits[tex_unit_id] = tex; break; } default: diff --git a/libopenage/renderer/opengl/shader_program.h b/libopenage/renderer/opengl/shader_program.h index 5d31f2a071..e5c75374c3 100644 --- a/libopenage/renderer/opengl/shader_program.h +++ b/libopenage/renderer/opengl/shader_program.h @@ -195,6 +195,7 @@ class GlShaderProgram final : public ShaderProgram std::unordered_map attribs; /// Store which texture handles are currently bound to the shader's texture units. + /// A value of std::nullopt means the texture unit is unbound (no texture assigned). std::vector> textures_per_texunits; /// Whether this program has been validated.