Merge pull request #801 from hartikainen:fix-mj_sizeModel
PiperOrigin-RevId: 522013801 Change-Id: Iff5e930fb7c86ae4296beb40f266ed02aabb6a7f
This commit is contained in:
+13
-2
@@ -803,8 +803,19 @@ void mj_deleteModel(mjModel* m) {
|
|||||||
|
|
||||||
// size of buffer needed to hold model
|
// size of buffer needed to hold model
|
||||||
int mj_sizeModel(const mjModel* m) {
|
int mj_sizeModel(const mjModel* m) {
|
||||||
return sizeof(int)*(4+getnint()) + sizeof(mjOption) +
|
int size = (
|
||||||
sizeof(mjVisual) + sizeof(mjStatistic) + m->nbuffer;
|
sizeof(int)*(4+getnint())
|
||||||
|
+ sizeof(mjOption)
|
||||||
|
+ sizeof(mjVisual)
|
||||||
|
+ sizeof(mjStatistic));
|
||||||
|
|
||||||
|
MJMODEL_POINTERS_PREAMBLE(m)
|
||||||
|
#define X(type, name, nr, nc) \
|
||||||
|
size += sizeof(type)*(m->nr)*(nc);
|
||||||
|
MJMODEL_POINTERS
|
||||||
|
#undef X
|
||||||
|
|
||||||
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,11 @@
|
|||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
@@ -47,6 +51,36 @@ mjModel PartialModel(const mjModel* m) {
|
|||||||
return partial_model;
|
return partial_model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(EngineIoTest, VerifySizeModel) {
|
||||||
|
constexpr char xml[] = R"(
|
||||||
|
<mujoco>
|
||||||
|
<worldbody>
|
||||||
|
<body>
|
||||||
|
<joint/>
|
||||||
|
<geom size="1"/>
|
||||||
|
</body>
|
||||||
|
</worldbody>
|
||||||
|
</mujoco>
|
||||||
|
)";
|
||||||
|
|
||||||
|
std::array<char, 1024> error;
|
||||||
|
mjModel* model = LoadModelFromString(xml, error.data(), error.size());
|
||||||
|
ASSERT_THAT(model, NotNull()) << "Failed to load model: " << error.data();
|
||||||
|
|
||||||
|
std::filesystem::path temp_file = (
|
||||||
|
std::filesystem::temp_directory_path() / "model.mjb");
|
||||||
|
|
||||||
|
mj_saveModel(model, temp_file.string().c_str(), NULL, 0);
|
||||||
|
|
||||||
|
std::uintmax_t file_size = std::filesystem::file_size(temp_file);
|
||||||
|
int model_size = mj_sizeModel(model);
|
||||||
|
|
||||||
|
std::filesystem::remove(temp_file);
|
||||||
|
mj_deleteModel(model);
|
||||||
|
|
||||||
|
EXPECT_EQ(file_size, model_size);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(EngineIoTest, MakeDataFromPartialModel) {
|
TEST_F(EngineIoTest, MakeDataFromPartialModel) {
|
||||||
constexpr char xml[] = R"(
|
constexpr char xml[] = R"(
|
||||||
<mujoco>
|
<mujoco>
|
||||||
|
|||||||
Reference in New Issue
Block a user