Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ inline void IncrSAP::addCollisionModel(core::CollisionModel *cm)
_nothing_added = false;

CubeCollisionModel * cube_model = dynamic_cast<CubeCollisionModel *>(cm->getLast()->getPrevious());
if (!cube_model)
return;
assert(cube_model->getPrevious() == cm->getFirst());

const int old_size = _boxes.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ bool LocalMinDistance::testValidity(Point &p, const Vec3 &PQ) const
const Vec3 pt = p.p();

const sofa::simulation::Node* node = dynamic_cast<sofa::simulation::Node*>(p.getCollisionModel()->getContext());
if ( !(node->get< LineCollisionModel<sofa::defaulttype::Vec3Types> >()) )
if ( !node || !(node->get< LineCollisionModel<sofa::defaulttype::Vec3Types> >()) )
return true;

BaseMeshTopology* topology = p.getCollisionModel()->getCollisionTopology();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ template<class DataTypes>
void StopperLagrangianConstraint<DataTypes>::init()
{
this->mstate = dynamic_cast<MechanicalState*>(this->getContext()->getMechanicalState());
assert(this->mstate);

helper::WriteAccessor<Data<VecCoord> > xData = *this->mstate->write(core::vec_id::write_access::position);
VecCoord& x = xData.wref();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,11 @@ sofa::component::statecontainer::MechanicalObject< DataTypes >* FixParticlePerfo
else if (b.mstate)
{
collisionState = dynamic_cast<MouseContainer*>(b.mstate);
fixPoint = (collisionState->read(core::vec_id::read_access::position)->getValue())[idx];
points.push_back(idx);
if (collisionState)
{
fixPoint = (collisionState->read(core::vec_id::read_access::position)->getValue())[idx];
points.push_back(idx);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ void MouseInteractor<DataTypes>::init()
{
BaseMouseInteractor::init();
mouseInSofa = dynamic_cast< MouseContainer*>(this->getContext()->getMechanicalState());
assert(mouseInSofa);
if (!mouseInSofa)
{
msg_error() << "MouseInteractor requires a MechanicalState of the correct type (" << DataTypes::Name() << ") in its context";
this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid);

return;
}
}

} // namespace sofa::gui::component::performer
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,12 @@ DefaultMultiMatrixAccessor::InteractionMatrixRef DefaultMultiMatrixAccessor::get
InteractionMatrixRef r2;
if (mstate1 == mstate2)// case where state1 == state2, interaction matrix is on the diagonal stiffness block
{
const MatrixRef r = diagonalStiffnessBloc.find(mstate1)->second;
const auto it = diagonalStiffnessBloc.find(mstate1);
if (it == diagonalStiffnessBloc.end())
{
return r2; // Return empty/default InteractionMatrixRef
}
const MatrixRef r = it->second;
r2.matrix = r.matrix;
r2.offRow = r.offset;
r2.offCol = r.offset;
Expand Down
8 changes: 5 additions & 3 deletions Sofa/framework/Helper/src/sofa/helper/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ const std::string& Utils::getUserHomeDirectory()
{
#ifdef WIN32 // Windows: ${HOME}
const char* homeDir = std::getenv("USERPROFILE");
return std::string(homeDir);
return homeDir ? std::string(homeDir) : std::string("");
#elif defined(__APPLE__) // macOS : ${HOME} (usually /Users/username)
glob_t globbuf;
if (glob("~", GLOB_TILDE, nullptr, &globbuf) == 0)
Expand Down Expand Up @@ -256,10 +256,12 @@ const std::string& Utils::getUserHomeDirectory()
if ((homeDir = std::getenv("HOME")) == nullptr)
{
// else system calls are used
homeDir = getpwuid(getuid())->pw_dir;
struct passwd* pw = getpwuid(getuid());
if (pw != nullptr)
homeDir = pw->pw_dir;
}

return std::string(homeDir);
return homeDir ? std::string(homeDir) : std::string("");

#endif
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ bool BaseMultiMappingElement::initNode()
for( iterState = inputStates.begin(); iterState != inputStates.end(); ++iterState)
{
simulation::Node* node = dynamic_cast< simulation::Node* >((*iterState)->getContext());
inputNodes.push_back(node);
if (node)
inputNodes.push_back(node);
}
/* */
/* get the Nodes corresponding to each output BaseState context */
for( iterState = outputStates.begin(); iterState != outputStates.end(); ++iterState)
{
simulation::Node* node = dynamic_cast< simulation::Node* >((*iterState)->getContext());
outputNodes.push_back(node);
if (node)
outputNodes.push_back(node);
}

type::vector<simulation::Node*>::iterator iterNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ void ArticulatedHierarchyContainer::init ()
for (; ac != acEnd; ac++)
{
context = dynamic_cast<simulation::Node *>((*ac)->getContext());
if (!context)
continue;
for (simulation::Node::ChildIterator it = context->child.begin(); it != context->child.end(); ++it)
{
simulation::Node* n = it->get();
Expand Down
12 changes: 8 additions & 4 deletions applications/plugins/Sensable/OmniDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,8 @@ void OmniDriver::handleEvent(core::objectmodel::Event *event)
Quat dummyQuat;
sofa::core::objectmodel::HapticDeviceEvent event(currentToolIndex,dummyVector,dummyQuat,buttonState);
simulation::Node *groot = dynamic_cast<simulation::Node *>(getContext()->getRootContext()); // access to current node
groot->propagateEvent(core::ExecParams::defaultInstance(), &event);
if (groot)
groot->propagateEvent(core::ExecParams::defaultInstance(), &event);
sofa::helper::AdvancedTimer::stepEnd("OmniDriver::6");
}

Expand Down Expand Up @@ -639,7 +640,8 @@ void OmniDriver::handleEvent(core::objectmodel::Event *event)
sofa::core::objectmodel::HapticDeviceEvent event(currentToolIndex,dummyVector,dummyQuat,
sofa::core::objectmodel::HapticDeviceEvent::Button1StateMask);
simulation::Node *groot = dynamic_cast<simulation::Node *>(getContext()->getRootContext()); // access to current node
groot->propagateEvent(core::ExecParams::defaultInstance(), &event);
if (groot)
groot->propagateEvent(core::ExecParams::defaultInstance(), &event);
}
if (kpe->getKey()=='J' || kpe->getKey()=='j')
{
Expand All @@ -649,7 +651,8 @@ void OmniDriver::handleEvent(core::objectmodel::Event *event)
sofa::core::objectmodel::HapticDeviceEvent event(currentToolIndex,dummyVector,dummyQuat,
sofa::core::objectmodel::HapticDeviceEvent::Button2StateMask);
simulation::Node *groot = dynamic_cast<simulation::Node *>(getContext()->getRootContext()); // access to current node
groot->propagateEvent(core::ExecParams::defaultInstance(), &event);
if (groot)
groot->propagateEvent(core::ExecParams::defaultInstance(), &event);
}

}
Expand All @@ -666,7 +669,8 @@ void OmniDriver::handleEvent(core::objectmodel::Event *event)
Quat dummyQuat;
sofa::core::objectmodel::HapticDeviceEvent event(currentToolIndex,dummyVector,dummyQuat,0);
simulation::Node *groot = dynamic_cast<simulation::Node *>(getContext()->getRootContext()); // access to current node
groot->propagateEvent(core::ExecParams::defaultInstance(), &event);
if (groot)
groot->propagateEvent(core::ExecParams::defaultInstance(), &event);
}
}
}
Expand Down
Loading