Skip to content

Commit

Permalink
Reset nnzJ in resetData.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 517976421
Change-Id: I329c0096d368062f150c6dbeec181f5b0eeefcbf
  • Loading branch information
kbayes authored and copybara-github committed Mar 20, 2023
1 parent e58d53e commit dfd463c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/engine/engine_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,7 @@ static void _resetData(const mjModel* m, mjData* d, unsigned char debug_value) {
d->ne = 0;
d->nf = 0;
d->nefc = 0;
d->nnzJ = 0;
d->ncon = 0;

// clear global properties
Expand Down
21 changes: 21 additions & 0 deletions test/engine/engine_io_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,27 @@ TEST_F(EngineIoTest, MakeDataReturnsNullOnFailure) {
mj_deleteModel(model);
}

TEST_F(EngineIoTest, ResetVariableSizes) {
constexpr char xml[] = "<mujoco/>";

std::array<char, 1024> error;
mjModel* model = LoadModelFromString(xml, error.data(), error.size());
ASSERT_THAT(model, NotNull()) << "Failed to load model: " << error.data();

mjData* data = mj_makeData(model);
ASSERT_THAT(model, NotNull()) << "Failed to create mjData";

// don't call mj_forward, vars should be reset
EXPECT_EQ(data->ne, 0);
EXPECT_EQ(data->nf, 0);
EXPECT_EQ(data->nefc, 0);
EXPECT_EQ(data->nnzJ, 0);
EXPECT_EQ(data->ncon, 0);

mj_deleteData(data);
mj_deleteModel(model);
}

using ValidateReferencesTest = MujocoTest;

TEST_F(ValidateReferencesTest, BodyReferences) {
Expand Down

0 comments on commit dfd463c

Please sign in to comment.