Skip to content

Commit 35ee3f0

Browse files
committed
Draft: Reducing memory leak in snapper - ussie #3340
1 parent b2cd2e0 commit 35ee3f0

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

src/Mod/Draft/DraftTools.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,12 @@ def getPoint(target,args,mobile=False,sym=False,workingplane=True,noTracker=Fals
127127
amod = hasMod(args,MODSNAP)
128128
cmod = hasMod(args,MODCONSTRAIN)
129129

130+
point = None
130131
if hasattr(FreeCADGui,"Snapper"):
131132
point = FreeCADGui.Snapper.snap(args["Position"],lastpoint=last,active=amod,constrain=cmod,noTracker=noTracker)
132133
info = FreeCADGui.Snapper.snapInfo
133134
mask = FreeCADGui.Snapper.affinity
134-
else:
135+
if not point:
135136
p = FreeCADGui.ActiveDocument.ActiveView.getCursorPos()
136137
point = FreeCADGui.ActiveDocument.ActiveView.getPoint(p)
137138
info = FreeCADGui.ActiveDocument.ActiveView.getObjectInfo(p)

src/Mod/Draft/DraftTrackers.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,16 @@ def __init__(self,dotted=False,scolor=None,swidth=None,ontop=False):
162162
def p1(self,point=None):
163163
"sets or gets the first point of the line"
164164
if point:
165-
self.coords.point.set1Value(0,point.x,point.y,point.z)
165+
if self.coords.point.getValues()[0].getValue() != tuple(point):
166+
self.coords.point.set1Value(0,point.x,point.y,point.z)
166167
else:
167168
return Vector(self.coords.point.getValues()[0].getValue())
168169

169170
def p2(self,point=None):
170171
"sets or gets the second point of the line"
171172
if point:
172-
self.coords.point.set1Value(1,point.x,point.y,point.z)
173+
if self.coords.point.getValues()[-1].getValue() != tuple(point):
174+
self.coords.point.set1Value(1,point.x,point.y,point.z)
173175
else:
174176
return Vector(self.coords.point.getValues()[-1].getValue())
175177

@@ -796,6 +798,7 @@ def __init__(self):
796798
mat3.diffuseColor.setValue(col)
797799
self.coords3 = coin.SoCoordinate3()
798800
self.lines3 = coin.SoLineSet()
801+
self.pts = []
799802
s = coin.SoSeparator()
800803
s.addChild(pick)
801804
s.addChild(self.trans)
@@ -832,24 +835,26 @@ def update(self):
832835
else:
833836
pts.extend([[-bound,curr,z],[bound,curr,z]])
834837
pts.extend([[curr,-bound,z],[curr,bound,z]])
835-
idx = []
836-
midx = []
837-
aidx = []
838-
for p in range(0,len(pts),2):
839-
idx.append(2)
840-
for mp in range(0,len(mpts),2):
841-
midx.append(2)
842-
for ap in range(0,len(apts),2):
843-
aidx.append(2)
844-
self.lines1.numVertices.deleteValues(0)
845-
self.lines2.numVertices.deleteValues(0)
846-
self.lines3.numVertices.deleteValues(0)
847-
self.coords1.point.setValues(pts)
848-
self.lines1.numVertices.setValues(idx)
849-
self.coords2.point.setValues(mpts)
850-
self.lines2.numVertices.setValues(midx)
851-
self.coords3.point.setValues(apts)
852-
self.lines3.numVertices.setValues(aidx)
838+
if pts != self.pts:
839+
idx = []
840+
midx = []
841+
aidx = []
842+
for p in range(0,len(pts),2):
843+
idx.append(2)
844+
for mp in range(0,len(mpts),2):
845+
midx.append(2)
846+
for ap in range(0,len(apts),2):
847+
aidx.append(2)
848+
self.lines1.numVertices.deleteValues(0)
849+
self.lines2.numVertices.deleteValues(0)
850+
self.lines3.numVertices.deleteValues(0)
851+
self.coords1.point.setValues(pts)
852+
self.lines1.numVertices.setValues(idx)
853+
self.coords2.point.setValues(mpts)
854+
self.lines2.numVertices.setValues(midx)
855+
self.coords3.point.setValues(apts)
856+
self.lines3.numVertices.setValues(aidx)
857+
self.pts = pts
853858

854859
def setSize(self,size):
855860
self.numlines = size

0 commit comments

Comments
 (0)