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.