Prevent deletion from an attached mjSpec.
This change disallows calling `mjs_delete` on an mjSpec that has been attached to another mjSpec via `mjs_attach`. Attempting to delete an element from an attached spec will now result in an error. The Python bindings for `mjSpec.delete` have been updated to raise a ValueError when this occurs. PiperOrigin-RevId: 897266695 Change-Id: Ic0670125a3028191ec50eca890f02b5910ec8b03
This commit is contained in:
committed by
Copybara-Service
parent
a744b366fb
commit
6b724616c0
@@ -474,8 +474,12 @@ int mj_copyBack(mjSpec* s, const mjModel* m) {
|
||||
// remove body from mjSpec, return 0 on success
|
||||
int mjs_delete(mjSpec* s, mjsElement* element) {
|
||||
mjCModel* model = static_cast<mjCModel*>(s->element);
|
||||
if (model->IsAttached()) {
|
||||
model->SetError(mjCError(nullptr, "Cannot delete element from an attached mjSpec."));
|
||||
return -1;
|
||||
}
|
||||
if (!element) {
|
||||
model->SetError(mjCError(0, "Element is null."));
|
||||
model->SetError(mjCError(nullptr, "Element is null."));
|
||||
return -1;
|
||||
}
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user