I am running into an issue I do not understand.
In this branch (_external_geometry_overconstrained_sketch_2), I have this commit:
https://github.com/abdullahtahiriyo/Fre ... 17500a544d
That introduces two functions:
Code: Select all
// retrieves an array of maps, each map containing the points that are coincidence by virtue of
// any number of direct or indirect coincidence constraints
const std::vector< std::map<int, Sketcher::PointPos> > & getCoincidenceGroups();
// returns if the given geoId is fixed (coincident) with external geometry on any of the possible relevant points
void isCoincidentWithExternalGeometry(int GeoId, bool &start_external, bool &mid_external, bool &end_external);
In this branch (_external_geometry_overconstrained_sketch_3), I have this commit:
https://github.com/abdullahtahiriyo/Fre ... f532c0a03d
which is just one commit over the contents of branch2.
The difference between branch3 and branch2 is:
Code: Select all
diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp
index cdb46e9..12f28f3 100644
--- a/src/Mod/Sketcher/App/SketchObject.cpp
+++ b/src/Mod/Sketcher/App/SketchObject.cpp
@@ -3143,7 +3143,54 @@ void SketchObject::isCoincidentWithExternalGeometry(int GeoId, bool &start_exter
const std::vector< Sketcher::Constraint * > &vals = Constraints.getValues();
- const std::vector< std::map<int, Sketcher::PointPos> > &coincidenttree = getCoincidenceGroups();
+ std::vector< std::map<int, Sketcher::PointPos> > coincidenttree;^M
+ // push the constraints^M
+ for (std::vector< Sketcher::Constraint * >::const_iterator it= vals.begin();it != vals.end(); ++it) {^M
+ if( (*it)->Type == Sketcher::Coincident ) {^M
+ int firstpresentin=-1;^M
+ int secondpresentin=-1;^M
+ ^M
+ int i=0;^M
+ ^M
+ for(std::vector< std::map<int, Sketcher::PointPos> >::const_iterator iti = coincidenttree.begin(); iti != coincidenttree.end(); ++iti,i++) {^M
+ // First^M
+ std::map<int, Sketcher::PointPos>::const_iterator filiterator;^M
+ filiterator = (*iti).find((*it)->First);^M
+ if( filiterator != (*iti).end()) {^M
+ if((*it)->FirstPos == (*filiterator).second)^M
+ firstpresentin = i;^M
+ }^M
+ // Second^M
+ filiterator = (*iti).find((*it)->Second);^M
+ if( filiterator != (*iti).end()) {^M
+ if((*it)->SecondPos == (*filiterator).second) ^M
+ secondpresentin = i;^M
+ } ^M
+ }^M will make FC crash whenever isCoincidentWithExternalGeometry is called
+ ^M
+ if ( firstpresentin!=-1 && secondpresentin!=-1) {^M
+ // we have to merge those sets into one^M
+ coincidenttree[firstpresentin].insert(coincidenttree[secondpresentin].begin(), coincidenttree[secondpresentin].end());^M
+ coincidenttree.erase(coincidenttree.begin()+secondpresentin);^M
+ }^M
+ else if ( firstpresentin==-1 && secondpresentin==-1 ) {^M
+ // we do not have any of the values, so create a setCursor^M
+ std::map<int, Sketcher::PointPos> tmp;^M
+ tmp.insert(std::pair<int, Sketcher::PointPos>((*it)->First,(*it)->FirstPos));^M
+ tmp.insert(std::pair<int, Sketcher::PointPos>((*it)->Second,(*it)->SecondPos));^M
+ coincidenttree.push_back(tmp);^M
+ }^M
+ else if ( firstpresentin != -1 ) {^M
+ // add to existing group^M
+ coincidenttree[firstpresentin].insert(std::pair<int, Sketcher::PointPos>((*it)->Second,(*it)->SecondPos));^M
+ }^M
+ else { // secondpresentin != -1^M
+ // add to existing group^M
+ coincidenttree[secondpresentin].insert(std::pair<int, Sketcher::PointPos>((*it)->First,(*it)->FirstPos));^M
+ }^M
+ ^M
+ }^M
+ }^M
for(std::vector< std::map<int, Sketcher::PointPos> >::const_iterator it = coincidenttree.begin(); it != coincidenttree.end(); ++it) {
Branch 3 works perfectly well and does not crash.
I think it may be related to the fact that I am returning by reference a local variable (yes, for a normal variable there is a memory leak because the variable is destroyed upon leaving the function, so the reference points to an address with invalid/destroyed data), but according to my knowledge of c++ (which may be wrong or outdated), it is perfectly ok to do that if the reference is const. In that specific case, the call to destroy the object is deferred to the point where the reference is destroyed.
I can not extract enough information from debugging with kdevelop branch 2 as to why it crashes. It does it, after several iterations in the loop in line (inside the STL find routine, at the compare subroutine):
Code: Select all
geoId1iterator = (*it).find(GeoId);
How to reproduce the crash:
1. Download the sketch of this post:
viewtopic.php?f=10&t=12254#p98522
2. Open Sketch6
3. Select create polyline, click coincident with the point on the vertical axis (the one that is not in the origin), next click on the point of the origin.
4. You should have crashed it by now.
Thanks in advance,
abdullah