Change LoadModelFromString to return a smart pointer, add MakeData, and update tests to have C++ RAII clean up model and data.

PiperOrigin-RevId: 935980153
Change-Id: I41d25bfab4935494dc984168820cb7cad123cadf
This commit is contained in:
Kyle Bayes
2026-06-22 04:18:29 -07:00
committed by Copybara-Service
parent 34d142ee50
commit 1490336955
39 changed files with 4616 additions and 5908 deletions
+6 -2
View File
@@ -157,7 +157,7 @@ const std::string GetModelPath(std::string_view path) { // NOLINT
return absl::StrCat("../model/", path);
}
mjModel* LoadModelFromString(std::string_view xml, char* error,
MjModelPtr LoadModelFromString(std::string_view xml, char* error,
int error_size, mjVFS* vfs) {
if (error) {
error[0] = '\0';
@@ -197,7 +197,11 @@ mjModel* LoadModelFromString(std::string_view xml, char* error,
}
SetGlobalXmlSpec(spec);
return model;
return MjModelPtr(model);
}
MjDataPtr MakeData(const MjModelPtr& model) {
return MjDataPtr(mj_makeData(model.get()));
}
static void AssertModelNotNull(mjModel* model,