Change tex_adr type to mjtSize.

Adds a test which verifies that we can index into the texture buffer at offsets larger than can be represented by a 32-bit signed int.

PiperOrigin-RevId: 868756646
Change-Id: Ibc1a2b269fce41aec370611b0aab77803837e7a8
This commit is contained in:
Adrian Collister
2026-02-11 11:06:21 -08:00
committed by Copybara-Service
parent 2b5afce4aa
commit d881e9e374
7 changed files with 34 additions and 7 deletions
+26
View File
@@ -16,6 +16,7 @@
#include <array>
#include <cmath>
#include <cstdint>
#include <limits>
#include <memory>
#include <string>
@@ -910,6 +911,31 @@ TEST_F(XMLReaderTest, LargeTextureTest) {
mj_deleteModel(model);
}
TEST_F(XMLReaderTest, LargeTextureAddressTest) {
static constexpr char xml[] = R"(
<mujoco>
<asset>
<!--
Test that tex_adr can correctly index into a texture buffer larger than
what a 32-bit signed integer can represent.
The first texture has size 6*10923*10923*3 > 2^31-1 bytes.
tex_adr[1] should correctly point beyond this offset.
-->
<texture name="tex0" builtin="gradient" width="10923" height="2"/>
<texture name="tex1" builtin="flat" width="2" height="2"/>
</asset>
</mujoco>
)";
std::array<char, 1024> error;
mjModel* model = LoadModelFromString(xml, error.data(), error.size());
ASSERT_THAT(model, NotNull()) << error.data();
EXPECT_EQ(model->ntex, 2);
EXPECT_GT(model->tex_adr[1], INT32_MAX);
mj_deleteModel(model);
}
TEST_F(XMLReaderTest, IncludeAssetsTest) {
static constexpr char xml[] = R"(
<mujoco>