Skip to content

Commit 03c1592

Browse files
committed
renderer: Fix tex unit assignment for std::optional type.
1 parent 02d3242 commit 03c1592

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

libopenage/renderer/opengl/shader_program.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,11 @@ void GlShaderProgram::update_uniforms(std::shared_ptr<GlUniformInput> const &uni
424424
glBindTexture(GL_TEXTURE_2D, tex);
425425
// TODO: maybe call this at a more appropriate position
426426
glUniform1i(loc, tex_unit_id);
427-
auto &tex_value = *this->textures_per_texunits[tex_unit_id];
428-
tex_value = tex;
427+
ENSURE(tex_unit_id < this->textures_per_texunits.size(),
428+
"Tried to assign texture to non-existant texture unit at index "
429+
<< tex_unit_id
430+
<< " (max: " << this->textures_per_texunits.size() << ").");
431+
this->textures_per_texunits[tex_unit_id] = tex;
429432
break;
430433
}
431434
default:

libopenage/renderer/opengl/shader_program.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class GlShaderProgram final : public ShaderProgram
195195
std::unordered_map<std::string, GlVertexAttrib> attribs;
196196

197197
/// Store which texture handles are currently bound to the shader's texture units.
198+
/// A value of std::nullopt means the texture unit is unbound (no texture assigned).
198199
std::vector<std::optional<GLuint>> textures_per_texunits;
199200

200201
/// Whether this program has been validated.

0 commit comments

Comments
 (0)