@@ -847,7 +847,7 @@ mjCBody& mjCBody::operator+=(const mjCBody& other) {
847
847
// map other frames to indices
848
848
std::map<mjCFrame*, int > fmap;
849
849
for (int i=0 ; i<other.frames .size (); i++) {
850
- fmap[other.frames [i]] = i;
850
+ fmap[other.frames [i]] = i + frames. size () ;
851
851
}
852
852
853
853
// copy frames, needs to happen first
@@ -977,6 +977,7 @@ template <typename T>
977
977
void mjCBody::CopyList (std::vector<T*>& dst, const std::vector<T*>& src,
978
978
std::map<mjCFrame*, int >& fmap, const mjCFrame* pframe) {
979
979
int nsrc = (int )src.size ();
980
+ int ndst = (int )dst.size ();
980
981
for (int i=0 ; i<nsrc; i++) {
981
982
if (pframe && !pframe->IsAncestor (src[i]->frame )) {
982
983
continue ; // skip if the element is not inside pframe
@@ -996,12 +997,19 @@ void mjCBody::CopyList(std::vector<T*>& dst, const std::vector<T*>& src,
996
997
dst.back ()->AddRef ();
997
998
}
998
999
999
- // assign dst frame to src frame
1000
- dst.back ()->frame = src[i]->frame ? frames[fmap[src[i]->frame ]] : nullptr ;
1001
-
1002
1000
// set namespace
1003
1001
dst.back ()->NameSpace (src[i]->model );
1004
1002
}
1003
+
1004
+ // assign dst frame to src frame
1005
+ // needs to be done after the copy in case T is an mjCFrame
1006
+ int j = 0 ;
1007
+ for (int i = 0 ; i < src.size (); i++) {
1008
+ if (pframe && !pframe->IsAncestor (src[i]->frame )) {
1009
+ continue ; // skip if the element is not inside pframe
1010
+ }
1011
+ dst[ndst + j++]->frame = src[i]->frame ? frames[fmap[src[i]->frame ]] : nullptr ;
1012
+ }
1005
1013
}
1006
1014
1007
1015
0 commit comments