From 931036adda9bdcbef25047d1d934d7a2df58f7ca Mon Sep 17 00:00:00 2001 From: Google DeepMind Date: Fri, 15 Aug 2025 09:52:39 -0700 Subject: [PATCH] Always try to find the skybox texture, even if there are no materials in the MJCF. Fixes #2412 Before the fix this only occured if the MJCF contained 0 materials. PiperOrigin-RevId: 795510952 Change-Id: I0a36c275e6006f80dc9a5ba6b9c6040ce21187c9 --- src/render/render_context.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/render/render_context.c b/src/render/render_context.c index b1f279bb..4a47f1df 100644 --- a/src/render/render_context.c +++ b/src/render/render_context.c @@ -1303,23 +1303,7 @@ static void makeMaterial(const mjModel* m, mjrContext* con) { memset(con->mat_texid, -1, sizeof(con->mat_texid)); memset(con->mat_texuniform, 0, sizeof(con->mat_texuniform)); memset(con->mat_texrepeat, 0, sizeof(con->mat_texrepeat)); - if (!m->nmat || !m->ntex) { - return; - } - if (m->nmat >= mjMAXMATERIAL-1) { - mju_error("Maximum number of materials is %d, got %d", mjMAXMATERIAL, m->nmat); - } - for (int i=0; i < m->nmat; i++) { - if (m->mat_texid[i*mjNTEXROLE + mjTEXROLE_RGB] >= 0) { - for (int j=0; j < mjNTEXROLE; j++) { - con->mat_texid[i*mjNTEXROLE + j] = m->mat_texid[i*mjNTEXROLE + j]; - } - con->mat_texuniform[i] = m->mat_texuniform[i]; - con->mat_texrepeat[2*i] = m->mat_texrepeat[2*i]; - con->mat_texrepeat[2*i+1] = m->mat_texrepeat[2*i+1]; - } - } // find skybox texture for (int i=0; i < m->ntex; i++) { if (m->tex_type[i] == mjTEXTURE_SKYBOX) { @@ -1335,6 +1319,20 @@ static void makeMaterial(const mjModel* m, mjrContext* con) { break; } } + + if (m->nmat >= mjMAXMATERIAL-1) { + mju_error("Maximum number of materials is %d, got %d", mjMAXMATERIAL, m->nmat); + } + for (int i=0; i < m->nmat; i++) { + if (m->mat_texid[i*mjNTEXROLE + mjTEXROLE_RGB] >= 0) { + for (int j=0; j < mjNTEXROLE; j++) { + con->mat_texid[i*mjNTEXROLE + j] = m->mat_texid[i*mjNTEXROLE + j]; + } + con->mat_texuniform[i] = m->mat_texuniform[i]; + con->mat_texrepeat[2*i] = m->mat_texrepeat[2*i]; + con->mat_texrepeat[2*i+1] = m->mat_texrepeat[2*i+1]; + } + } }