Skip to content

Commit 3f2de38

Browse files
mpoudotlelandaisb
authored andcommitted
Avoid segfault when importing a curve where the start point is the same as the end point
1 parent 0a9164c commit 3f2de38

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

src/Core/Internal/ImportMDLImplementation.cpp

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -633,16 +633,16 @@ Geom::Curve* ImportMDLImplementation::getCurve(const std::string name)
633633
Geom::Vertex* vtx2 = getVertex(current_command.model1d.pt2);
634634
if(vtx1!=vtx2)
635635
{
636-
crv = Geom::EntityFactory(m_context).newSegment(vtx1,vtx2);
636+
crv = Geom::EntityFactory(m_context).newSegment(vtx1,vtx2);
637637

638-
//creation des connections topologiques
639-
crv->add(vtx1);
640-
crv->add(vtx2);
641-
vtx1->add(crv);
642-
vtx2->add(crv);
638+
//creation des connections topologiques
639+
crv->add(vtx1);
640+
crv->add(vtx2);
641+
vtx1->add(crv);
642+
vtx2->add(crv);
643643
}
644644
else {
645-
//std::cerr<<"IMPORT D'UN SEGMENT DE LONGUEUR NULLE NON EFFECTUEE ("<<name<<")"<<std::endl;
645+
//std::cerr<<"IMPORT D'UN SEGMENT DE LONGUEUR NULLE NON EFFECTUE ("<<name<<")"<<std::endl;
646646
TkUtil::UTF8String messErr (TkUtil::Charset::UTF_8);
647647
messErr << "On ne peut créer un segment de taille nulle pour "<<name;
648648
throw TkUtil::Exception(messErr);
@@ -656,19 +656,28 @@ Geom::Curve* ImportMDLImplementation::getCurve(const std::string name)
656656
Geom::Vertex* vtxcenter = getVertex(current_command.u.arc.center);
657657
bool dir = bool(current_command.u.arc.direction);
658658
//std::cout<<"direction = "<<current_command.u.arc.direction<<" => dir = "<<(dir?"true":"false")<<std::endl;
659-
if(current_command.u.arc.is_circle)
660-
crv = Geom::EntityFactory(m_context).newArcCircle2D(vtxcenter,vtx1,vtx2, dir);
661-
else
662-
crv = Geom::EntityFactory(m_context).newArcEllipse(vtxcenter,vtx1,vtx2, dir);
663-
664-
//creation des connections topologiques
665-
crv->add(vtx1);
666-
vtx1->add(crv);
667-
if(vtx2!=vtx1){
668-
crv->add(vtx2);
669-
vtx2->add(crv);
659+
if(vtx1!=vtx2)
660+
{
661+
if(current_command.u.arc.is_circle)
662+
crv = Geom::EntityFactory(m_context).newArcCircle2D(vtxcenter,vtx1,vtx2, dir);
663+
else
664+
crv = Geom::EntityFactory(m_context).newArcEllipse(vtxcenter,vtx1,vtx2, dir);
665+
666+
//creation des connections topologiques
667+
crv->add(vtx1);
668+
vtx1->add(crv);
669+
if(vtx2!=vtx1){
670+
crv->add(vtx2);
671+
vtx2->add(crv);
672+
}
670673
}
671-
}
674+
else {
675+
//std::cerr<<"IMPORT D'UNE COURBE AVEC DEUX POINTS IDENTIQUES NON EFFECTUE ("<<name<<")"<<std::endl;
676+
TkUtil::UTF8String messErr (TkUtil::Charset::UTF_8);
677+
messErr << "On ne peut créer une courbe avec un point de départ et un point d'arrivée identiques pour "<<name;
678+
throw TkUtil::Exception(messErr);
679+
}
680+
}
672681
else if (current_command.type == MdlLine){
673682
// on va créer des Vertex même pour les points interne au support
674683
// de manière à rendre se dernier modifiable

0 commit comments

Comments
 (0)