Skip to content

Commit aaa29fd

Browse files
authored
[XML] Error handling when parsing (#6149)
1 parent 4006d81 commit aaa29fd

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

Sofa/framework/Simulation/Common/src/sofa/simulation/common/xml/ObjectElement.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,26 @@ bool ObjectElement::init()
5656

5757
bool ObjectElement::initNode()
5858
{
59-
core::objectmodel::BaseContext* ctx = getParent()->getObject()->toBaseContext();
59+
core::objectmodel::BaseContext* ctx { nullptr };
60+
if (auto* parent = getParent())
61+
{
62+
if (auto* parentObj = parent->getObject())
63+
{
64+
ctx = parentObj->toBaseContext();
65+
}
66+
else
67+
{
68+
msg_error("XML parser") << "Cannot access to a valid component from parent element \'"
69+
<< parent->getName() << "\' (type:\'" << parent->getAttribute("type")
70+
<< "\') for the object element \'" << this->getName() << "\'";
71+
}
72+
}
73+
else
74+
{
75+
msg_error("XML parser") << "Cannot find a parent for the object element \'" << this->getName() << "\'";
76+
}
77+
if (!ctx)
78+
return false;
6079

6180
for (AttributeMap::iterator it = attributes.begin(), itend = attributes.end(); it != itend; ++it)
6281
{

0 commit comments

Comments
 (0)