Migrate mjModel size fields from int to mjtSize.

This change updates all size-related members within the `mjModel` struct from `int` to `mjtSize`. This allows MuJoCo to handle models with a larger number of elements. Corresponding changes were made to macros, function signatures, and I/O routines to accommodate the new `mjtSize` type.

PiperOrigin-RevId: 860144595
Change-Id: I701c6d607715d240766b6210a9773cd9e4258c59
This commit is contained in:
Yuval Tassa
2026-01-23 09:40:42 -08:00
committed by Copybara-Service
parent 4a64017a5f
commit 30b903b6c0
24 changed files with 832 additions and 802 deletions
+5 -1
View File
@@ -203,6 +203,10 @@ auto Compare(unsigned char val1, unsigned char val2) {
return val1 != val2;
}
auto Compare(mjtSize val1, mjtSize val2) {
return val1 > val2 ? val1 - val2 : val2 - val1;
}
// The maximum spacing between a normalised floating point number x and an
// adjacent normalised number is 2 epsilon |x|; a factor 10 is added accounting
// for losses during non-idempotent operations such as vector normalizations.
@@ -245,7 +249,7 @@ mjtNum CompareModel(const mjModel* m1, const mjModel* m2,
field = #name; \
} \
}
MJMODEL_INTS
MJMODEL_SIZES
#undef X
if (maxdif > 0) return maxdif;
+1 -1
View File
@@ -126,7 +126,7 @@ TEST_F(HeaderTest, MjModelIntsOrdered) {
std::vector<std::pair<const void*, const char*>> ints;
#define X(name) ints.push_back({static_cast<const void*>(&m.name), #name});
MJMODEL_INTS
MJMODEL_SIZES
#undef X
CheckAddressOrdering(ints, "MJMODEL_INT");
+5 -28
View File
@@ -892,11 +892,11 @@ TEST_F(XMLReaderTest, LargeTextureTest) {
<mujoco>
<asset>
<!--
Use a texture width that exceeds the maximum texture size. For cube
textures, the height is ignored and set to width*6. The default number of
channels is 3.
Use a texture width that exceeds the size representable by an int.
For cube textures, the height is ignored and set to width*6.
The default number of channels is 3.
The width in this test is chosen so that 6*width*width*3 is too large to
be represented as an integer.
be represented as a 32-bit integer.
-->
<texture name="tex" builtin="gradient" width="10923" height="2"/>
</asset>
@@ -906,30 +906,7 @@ TEST_F(XMLReaderTest, LargeTextureTest) {
std::array<char, 1024> error;
mjModel* model = LoadModelFromString(xml, error.data(), error.size());
EXPECT_THAT(model, IsNull());
mj_deleteModel(model);
}
TEST_F(XMLReaderTest, HugeTextureTest) {
static constexpr char xml[] = R"(
<mujoco>
<asset>
<!--
Use a texture width that exceeds the maximum texture size. For cube
textures, the height is ignored and set to width*6. The default number of
channels is 3.
The width in this test is chosen so that 6*width*width*3 is so large that
it overflows and becomes a positive integer.
-->
<texture name="tex" builtin="gradient" width="15447" height="2"/>
</asset>
</mujoco>
)";
std::array<char, 1024> error;
mjModel* model = LoadModelFromString(xml, error.data(), error.size());
EXPECT_THAT(model, IsNull());
EXPECT_THAT(model, NotNull());
mj_deleteModel(model);
}