yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #02355
Re: Engine crash
> InteractionContainer::iterator ii =
> rootBody->interactions->begin();
> InteractionContainer::iterator iiEnd =
> rootBody->interactions->end();
> numberCohesiveContacts=0;
> for(; ii!=iiEnd; ++ii ) {
> const shared_ptr<Interaction>& interaction = *ii;
> RpmPhys* contPhys =
> static_cast<RpmPhys*>(interaction->interactionPhysics.get());
> if (contPhys->isCohesive==true) {
> numberCohesiveContacts++;
> }
> }
Do it like this:
FOREACH(const shared_ptr<Interaction>& i, *rootBody->interactions){
if(!i->isReal()) continue;
/* handle interactions */
}
1. use FOREACH, it is easier to read, write and equally fast.
2. Check isReal, otherwise you get also "potential" interactions, which
have NULL interactionGeometry and interactionsPhysics, hence the crash.
3. I suggest you use
YADE_PTR_CAST<RpmPhys>(interaction->interactionPhysics) /* I think
speedwise there is no difference between const ref to shared_ptr or
const ptr */ instead of static_cast. It allows you to trap bad types in
the debug build (nice assertion failure dereferencing NULL shared_ptr)
instead of doing weird things, and it has no performance penaly in the
optimized build.
HTH, Vaclav
> #4 <signal handler called>
> #5 0x00007f22dc46452e in CohesiveStateRPMRecorder::action
> (this=0x4490c50, rootBody=0xf3d400)
> at /home/gladk/dem/yade/currentMono/yade/pkg/dem/Engine/StandAloneEngine/CohesiveStateRPMRecorder.cpp:30
(Huh, not very useful as we don't know what is line 30...)
PS. I will create Recorder class deriving from PeriodicEngine. It will
handle opening the file for you; there is many classes that need it...
PPS You can also use the plotting framework to get this kind of data at
runtime, without writing to file. It is much more flexible. You can e.g.
write a function in _utils.cpp that will do it and call it every time
you need.
Follow ups
References