Add error checking in mjs_setFrame.
Also raise error if the frame is not found in the mjCBody copy constructor. Fixes #2543. PiperOrigin-RevId: 742624013 Change-Id: I4999b3165c97f8d079412214d027ca7a8dae8cb3
This commit is contained in:
committed by
Copybara-Service
parent
ebd30493c8
commit
86c970bc23
@@ -773,6 +773,9 @@ void mjCBase::SetFrame(mjCFrame* _frame) {
|
||||
if (!_frame) {
|
||||
return;
|
||||
}
|
||||
if (_frame->body && GetParent() != _frame->body) {
|
||||
throw mjCError(this, "Frame and body '%s' have mismatched parents", name.c_str());
|
||||
}
|
||||
frame = _frame;
|
||||
}
|
||||
|
||||
@@ -891,8 +894,18 @@ mjCBody& mjCBody::operator+=(const mjCBody& other) {
|
||||
for (int i=0; i < other.bodies.size(); i++) {
|
||||
bodies.push_back(new mjCBody(*other.bodies[i], model)); // triggers recursive call
|
||||
bodies.back()->parent = this;
|
||||
bodies.back()->frame =
|
||||
other.bodies[i]->frame ? frames[fmap[other.bodies[i]->frame]] : nullptr;
|
||||
bodies.back()->frame = nullptr;
|
||||
if (other.bodies[i]->frame) {
|
||||
if (fmap.find(other.bodies[i]->frame) != fmap.end()) {
|
||||
bodies.back()->frame = frames[fmap[other.bodies[i]->frame]];
|
||||
} else {
|
||||
throw mjCError(this, "Frame '%s' not found in other body",
|
||||
other.bodies[i]->frame->name.c_str());
|
||||
}
|
||||
if (bodies.back()->frame && bodies.back()->frame->body != this) {
|
||||
throw mjCError(this, "Frame and body '%s' have mismatched parents", name.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
|
||||
Reference in New Issue
Block a user