Check for texid >= 0 before accessing texture arrays.

PiperOrigin-RevId: 659567553
Change-Id: Ia4aaa85b85e3f27e632c03a9f50b10894d29a97b
This commit is contained in:
Nimrod Gileadi
2024-08-05 08:46:48 -07:00
committed by Copybara-Service
parent 0610c1d0e9
commit 4dc8f884de
+3 -3
View File
@@ -95,7 +95,7 @@ static void settexture(int type, int state, const mjrContext* con, const mjvGeom
// explicit texture coordinates // explicit texture coordinates
else if (type == mjtexREGULAR && geom->texcoord) { else if (type == mjtexREGULAR && geom->texcoord) {
// enable // enable
if (state) { if (state && texid >= 0) {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, con->texture[texid]); glBindTexture(GL_TEXTURE_2D, con->texture[texid]);
@@ -109,7 +109,7 @@ static void settexture(int type, int state, const mjrContext* con, const mjvGeom
} }
// 2D // 2D
else if (type == mjtexREGULAR && con->textureType[texid] == mjTEXTURE_2D) { else if (type == mjtexREGULAR && texid >= 0 && con->textureType[texid] == mjTEXTURE_2D) {
// enable // enable
if (state) { if (state) {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
@@ -161,7 +161,7 @@ static void settexture(int type, int state, const mjrContext* con, const mjvGeom
// cube or skybox // cube or skybox
else { else {
// enable // enable
if (state) { if (state && texid >= 0) {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_CUBE_MAP); glEnable(GL_TEXTURE_CUBE_MAP);
glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_S);