~ubuntu-branches/debian/jessie/yade/jessie

« back to all changes in this revision

Viewing changes to .pc/03_fix_segfault_clumps.patch/core/BodyContainer.cpp

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2014-08-11 22:23:05 UTC
  • Revision ID: package-import@ubuntu.com-20140811222305-9j9km3y0l7h336wc
Tags: 1.11.0-2
* [85ceffc] Fix autotest DEM-PFV. (Closes: #757576)
* [672fa7a] Let build-indep target be built.
* [ca274c2] Apply upstream fix: segfault on removing clumps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 2010 © Václav Šmilauer <eudoxos@arcig.cz>
 
2
 
 
3
#include "Scene.hpp"
 
4
#include "Body.hpp"
 
5
#include "BodyContainer.hpp"
 
6
#include "Clump.hpp"
 
7
#ifdef YADE_OPENMP
 
8
        #include<omp.h>
 
9
#endif
 
10
 
 
11
 
 
12
CREATE_LOGGER(BodyContainer);
 
13
 
 
14
void BodyContainer::clear(){
 
15
        body.clear();
 
16
}
 
17
 
 
18
Body::id_t BodyContainer::insert(shared_ptr<Body>& b){
 
19
        const shared_ptr<Scene>& scene=Omega::instance().getScene(); 
 
20
        b->iterBorn=scene->iter;
 
21
        b->timeBorn=scene->time;
 
22
        b->id=body.size();
 
23
        scene->doSort = true;
 
24
        body.push_back(b);
 
25
        // Notify ForceContainer about new id
 
26
        scene->forces.addMaxId(b->id);
 
27
        return b->id;
 
28
}
 
29
 
 
30
bool BodyContainer::erase(Body::id_t id, bool eraseClumpMembers){//default is false (as before)
 
31
        if(!body[id]) return false;
 
32
        
 
33
        const shared_ptr<Body>& b=Body::byId(id);
 
34
        
 
35
        if ((b) and (b->isClumpMember())) {
 
36
                const shared_ptr<Body>& clumpBody=Body::byId(b->clumpId);
 
37
                const shared_ptr<Clump> clump=YADE_PTR_CAST<Clump>(clumpBody->shape);
 
38
                Clump::del(clumpBody, b);
 
39
                
 
40
                if (clump->members.size()==0) this->erase(b->clumpId,false);    //Clump has no members any more. Remove it
 
41
        }
 
42
        
 
43
        if ((b) and (b->isClump())){
 
44
                //erase all members if eraseClumpMembers is true:
 
45
                const shared_ptr<Clump>& clump=YADE_PTR_CAST<Clump>(b->shape);
 
46
                std::map<Body::id_t,Se3r>& members = clump->members;
 
47
                FOREACH(MemberMap::value_type& mm, members){
 
48
                        const Body::id_t& memberId=mm.first;
 
49
                        if (eraseClumpMembers) this->erase(memberId,false);     // erase members
 
50
                        //when the last members is erased, the clump will be erased automatically, see above
 
51
                        else Body::byId(memberId)->clumpId=Body::id_t(-1);      // make members standalones
 
52
                }
 
53
        }
 
54
        const shared_ptr<Scene>& scene=Omega::instance().getScene();
 
55
        for(Body::MapId2IntrT::iterator it=b->intrs.begin(),end=b->intrs.end(); it!=end; ++it) {  //Iterate over all body's interactions
 
56
                scene->interactions->requestErase((*it).second);
 
57
        }
 
58
        
 
59
        body[id].reset();
 
60
        
 
61
        return true;
 
62
}