Fix bug in RemoveFromList.
The function was interpreting that the elements that were expected to be detached contained useful user errors, and therefore it was not detaching them. Also, the function tried to compare the namespace between two models, but the namespace is already fused in the references at detach time. PiperOrigin-RevId: 651738364 Change-Id: Ifdaa9bd5b658bfd18b544b7138a5c2c56b66e936
This commit is contained in:
committed by
Copybara-Service
parent
f1aa52aa9b
commit
6e64dd10e8
+11
-15
@@ -168,6 +168,7 @@ void mjCModel::CopyList(std::vector<T*>& dest,
|
||||
candidate->ResolveReferences(this);
|
||||
} catch (mjCError err) {
|
||||
// if not present, skip the element
|
||||
// TODO: do not skip elements that contain user errors
|
||||
delete candidate;
|
||||
continue;
|
||||
}
|
||||
@@ -256,25 +257,20 @@ mjCModel& mjCModel::operator+=(const mjCModel& other) {
|
||||
|
||||
|
||||
template <class T>
|
||||
void mjCModel::RemoveFromList(std::vector<T*>& list, const mjCModel& other) {
|
||||
void mjCModel::RemoveFromList(std::vector<T*>& list) {
|
||||
int nlist = (int)list.size();
|
||||
int removed = 0;
|
||||
for (int i = 0; i < nlist; i++) {
|
||||
T* element = list[i];
|
||||
element->id -= removed;
|
||||
try {
|
||||
// check if the element contains an error
|
||||
element->NameSpace(&other);
|
||||
element->CopyFromSpec();
|
||||
element->ResolveReferences(&other);
|
||||
} catch (mjCError err) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
// check if the element references something that was removed
|
||||
// TODO: do not remove elements that contain user errors
|
||||
element->NameSpace(this);
|
||||
element->CopyFromSpec();
|
||||
element->ResolveReferences(this);
|
||||
} catch (mjCError err) {
|
||||
ids[element->elemtype].erase(element->name);
|
||||
delete element;
|
||||
list.erase(list.begin() + i);
|
||||
nlist--;
|
||||
@@ -315,12 +311,12 @@ mjCModel& mjCModel::operator-=(const mjCBody& subtree) {
|
||||
ProcessLists(/*checkrepeat=*/false);
|
||||
|
||||
// check if we have to remove anything else
|
||||
RemoveFromList(pairs_, oldmodel);
|
||||
RemoveFromList(excludes_, oldmodel);
|
||||
RemoveFromList(tendons_, oldmodel);
|
||||
RemoveFromList(equalities_, oldmodel);
|
||||
RemoveFromList(actuators_, oldmodel);
|
||||
RemoveFromList(sensors_, oldmodel);
|
||||
RemoveFromList(pairs_);
|
||||
RemoveFromList(excludes_);
|
||||
RemoveFromList(tendons_);
|
||||
RemoveFromList(equalities_);
|
||||
RemoveFromList(actuators_);
|
||||
RemoveFromList(sensors_);
|
||||
|
||||
// restore to the original state
|
||||
if (!compiled) {
|
||||
|
||||
@@ -342,8 +342,8 @@ class mjCModel : public mjCModel_, private mjSpec {
|
||||
template <class T> void CopyList(std::vector<T*>& dest,
|
||||
const std::vector<T*>& sources);
|
||||
|
||||
// delete from list the elements that are compatible with other but not this model
|
||||
template <class T> void RemoveFromList(std::vector<T*>& list, const mjCModel& other);
|
||||
// delete from list the elements that cause an error
|
||||
template <class T> void RemoveFromList(std::vector<T*>& list);
|
||||
|
||||
// create mjCBase lists from children lists
|
||||
void CreateObjectLists();
|
||||
|
||||
Vendored
+1
-17
@@ -23,22 +23,6 @@
|
||||
</tendon>
|
||||
|
||||
<actuator>
|
||||
<position name="b00" tendon="b00" ctrlrange="0 3" kp="100" dampratio="1"/>
|
||||
<position name="b01" tendon="b01" ctrlrange="0 3" kp="100" dampratio="1"/>
|
||||
<position name="b02" tendon="b02" ctrlrange="0 3" kp="100" dampratio="1"/>
|
||||
<position name="b03" tendon="b03" ctrlrange="0 3" kp="100" dampratio="1"/>
|
||||
<position name="b04" tendon="b04" ctrlrange="0 3" kp="100" dampratio="1"/>
|
||||
<position name="b05" tendon="b05" ctrlrange="0 3" kp="100" dampratio="1"/>
|
||||
<position name="b06" tendon="b06" ctrlrange="0 3" kp="100" dampratio="1"/>
|
||||
<position name="b07" tendon="b07" ctrlrange="0 3" kp="100" dampratio="1"/>
|
||||
<position name="b08" tendon="b08" ctrlrange="0 3" kp="100" dampratio="1"/>
|
||||
<position name="b09" tendon="b09" ctrlrange="0 3" kp="100" dampratio="1"/>
|
||||
<position name="b10" tendon="b10" ctrlrange="0 3" kp="100" dampratio="1"/>
|
||||
<position name="b11" tendon="b11" ctrlrange="0 3" kp="100" dampratio="1"/>
|
||||
<position name="b12" tendon="b12" ctrlrange="0 3" kp="100" dampratio="1"/>
|
||||
<position name="b13" tendon="b13" ctrlrange="0 3" kp="100" dampratio="1"/>
|
||||
<position name="b14" tendon="b14" ctrlrange="0 3" kp="100" dampratio="1"/>
|
||||
<position name="b15" tendon="b15" ctrlrange="0 3" kp="100" dampratio="1"/>
|
||||
<position name="b16" tendon="b16" ctrlrange="0 3" kp="100" dampratio="1"/>
|
||||
<position name="b" tendon="b" ctrlrange="0 3" kp="100" dampratio="1"/>
|
||||
</actuator>
|
||||
</mujoco>
|
||||
|
||||
Reference in New Issue
Block a user