From 5c23ae11efc58653ec836caf8755239d2d37c04b Mon Sep 17 00:00:00 2001 From: Yuval Tassa Date: Tue, 19 Nov 2024 06:29:49 -0800 Subject: [PATCH] Fix bug in material `texrepeat` attribute, fixes #2223. Was mistakenly cast from float to int, bug introduced in 3.2.0 PiperOrigin-RevId: 697993181 Change-Id: I643a07e2b0866a4af56d7cbd3344e764a7caf56f --- doc/changelog.rst | 2 ++ doc/includes/references.h | 18 +++++++++--------- include/mujoco/mjrender.h | 18 +++++++++--------- introspect/structs.py | 4 ++-- src/render/render_context.c | 6 +++--- unity/Runtime/Bindings/MjBindings.cs | 2 +- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index 87225bea..dafe7daf 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -13,6 +13,8 @@ MJX Bug fixes ^^^^^^^^^ - Fixed :github:issue:`2212`, type error in ``mjx.get_data``. +- Fixed bug introduced in 3.2.0 in handling of :ref:`texrepeat` attribute, was mistakenly cast + from ``float`` to ``int``, (fixed :github:issue:`2223`). Version 3.2.5 (Nov 4, 2024) --------------------------- diff --git a/doc/includes/references.h b/doc/includes/references.h index 4d4c6b98..ac6c4b35 100644 --- a/doc/includes/references.h +++ b/doc/includes/references.h @@ -1582,14 +1582,14 @@ struct mjrContext_ { // custom OpenGL context unsigned int auxColor_r[mjNAUX]; // auxiliary color buffer for resolving // materials with textures - int mat_texid[mjMAXMATERIAL*mjNTEXROLE]; // material texture ids (-1: no texture) - int mat_texuniform[mjMAXMATERIAL]; // texture repetition for 2d mapping - int mat_texrepeat[mjMAXMATERIAL*2]; // texture repetition for 2d mapping + int mat_texid[mjMAXMATERIAL*mjNTEXROLE]; // material texture ids (-1: no texture) + int mat_texuniform[mjMAXMATERIAL]; // uniform cube mapping + float mat_texrepeat[mjMAXMATERIAL*2]; // texture repetition for 2d mapping // texture objects and info - int ntexture; // number of allocated textures - int textureType[mjMAXTEXTURE]; // type of texture (mjtTexture) (ntexture) - unsigned int texture[mjMAXTEXTURE]; // texture names + int ntexture; // number of allocated textures + int textureType[mjMAXTEXTURE]; // type of texture (mjtTexture) (ntexture) + unsigned int texture[mjMAXTEXTURE]; // texture names // displaylist starting positions unsigned int basePlane; // all planes from model @@ -1628,13 +1628,13 @@ struct mjrContext_ { // custom OpenGL context int windowDoublebuffer; // is default/window framebuffer double buffered // framebuffer - int currentBuffer; // currently active framebuffer: mjFB_WINDOW or mjFB_OFFSCREEN + int currentBuffer; // currently active framebuffer: mjFB_WINDOW or mjFB_OFFSCREEN // pixel output format - int readPixelFormat; // default color pixel format for mjr_readPixels + int readPixelFormat; // default color pixel format for mjr_readPixels // depth output format - int readDepthMap; // depth mapping: mjDEPTH_ZERONEAR or mjDEPTH_ZEROFAR + int readDepthMap; // depth mapping: mjDEPTH_ZERONEAR or mjDEPTH_ZEROFAR }; typedef struct mjrContext_ mjrContext; typedef enum mjtGeomInertia_ { // type of inertia inference diff --git a/include/mujoco/mjrender.h b/include/mujoco/mjrender.h index ff9dbe34..9a8ed1b7 100644 --- a/include/mujoco/mjrender.h +++ b/include/mujoco/mjrender.h @@ -115,14 +115,14 @@ struct mjrContext_ { // custom OpenGL context unsigned int auxColor_r[mjNAUX]; // auxiliary color buffer for resolving // materials with textures - int mat_texid[mjMAXMATERIAL*mjNTEXROLE]; // material texture ids (-1: no texture) - int mat_texuniform[mjMAXMATERIAL]; // texture repetition for 2d mapping - int mat_texrepeat[mjMAXMATERIAL*2]; // texture repetition for 2d mapping + int mat_texid[mjMAXMATERIAL*mjNTEXROLE]; // material texture ids (-1: no texture) + int mat_texuniform[mjMAXMATERIAL]; // uniform cube mapping + float mat_texrepeat[mjMAXMATERIAL*2]; // texture repetition for 2d mapping // texture objects and info - int ntexture; // number of allocated textures - int textureType[mjMAXTEXTURE]; // type of texture (mjtTexture) (ntexture) - unsigned int texture[mjMAXTEXTURE]; // texture names + int ntexture; // number of allocated textures + int textureType[mjMAXTEXTURE]; // type of texture (mjtTexture) (ntexture) + unsigned int texture[mjMAXTEXTURE]; // texture names // displaylist starting positions unsigned int basePlane; // all planes from model @@ -161,13 +161,13 @@ struct mjrContext_ { // custom OpenGL context int windowDoublebuffer; // is default/window framebuffer double buffered // framebuffer - int currentBuffer; // currently active framebuffer: mjFB_WINDOW or mjFB_OFFSCREEN + int currentBuffer; // currently active framebuffer: mjFB_WINDOW or mjFB_OFFSCREEN // pixel output format - int readPixelFormat; // default color pixel format for mjr_readPixels + int readPixelFormat; // default color pixel format for mjr_readPixels // depth output format - int readDepthMap; // depth mapping: mjDEPTH_ZERONEAR or mjDEPTH_ZEROFAR + int readDepthMap; // depth mapping: mjDEPTH_ZERONEAR or mjDEPTH_ZEROFAR }; typedef struct mjrContext_ mjrContext; diff --git a/introspect/structs.py b/introspect/structs.py index bed95997..c50bea6e 100644 --- a/introspect/structs.py +++ b/introspect/structs.py @@ -8596,12 +8596,12 @@ STRUCTS: Mapping[str, StructDecl] = dict([ inner_type=ValueType(name='int'), extents=(1000,), ), - doc='texture repetition for 2d mapping', + doc='uniform cube mapping', ), StructFieldDecl( name='mat_texrepeat', type=ArrayType( - inner_type=ValueType(name='int'), + inner_type=ValueType(name='float'), extents=(2000,), ), doc='texture repetition for 2d mapping', diff --git a/src/render/render_context.c b/src/render/render_context.c index 4c6c3879..b0b2a361 100644 --- a/src/render/render_context.c +++ b/src/render/render_context.c @@ -1304,7 +1304,7 @@ static void makeMaterial(const mjModel* m, mjrContext* con) { } if (m->nmat >= mjMAXMATERIAL-1) { - mju_error("Maximum number of materials is 100, got %d", m->nmat); + 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) { @@ -1320,8 +1320,8 @@ static void makeMaterial(const mjModel* m, mjrContext* con) { for (int i=0; i < m->ntex; i++) { if (m->tex_type[i] == mjTEXTURE_SKYBOX) { if (m->nmat >= mjMAXMATERIAL-2) { - mju_error("With skybox, maximum number of materials is 99, got %d", - m->nmat); + mju_error("With skybox, maximum number of materials is %d, got %d", + mjMAXMATERIAL-1, m->nmat); } for (int j=0; j < mjNTEXROLE; j++) { con->mat_texid[mjNTEXROLE * (mjMAXMATERIAL-1) + j] = -1; diff --git a/unity/Runtime/Bindings/MjBindings.cs b/unity/Runtime/Bindings/MjBindings.cs index 358787c1..a8d063be 100644 --- a/unity/Runtime/Bindings/MjBindings.cs +++ b/unity/Runtime/Bindings/MjBindings.cs @@ -5681,7 +5681,7 @@ public unsafe struct mjrContext_ { public fixed uint auxColor_r[10]; public fixed int mat_texid[10000]; public fixed int mat_texuniform[1000]; - public fixed int mat_texrepeat[2000]; + public fixed float mat_texrepeat[2000]; public int ntexture; public fixed int textureType[1000]; public fixed uint texture[1000];