edit. Solved. The problem was I was initially setting up the vertices using a vertex writer named self.vertex, and later editing them using one named vertex.The pointer to self.vertex remained, and memory filled up.

Hi all. I am writing a game featuring a 2d planet simulator. The world is comprised of number of layers of rock, like Terraria, but the world is circular like Reus rather than rectangular.

I have a large procedurally generated geom to display the arcs of rock. When the world is changed (eg, by the player mining, or placing a block) I loop through the vertices in the geoms and update their positions and colors using setData3f and setData4f, respectively. After the geoms are initially built, I never use addData.

Every time I update the geom (running setData on every vertex in the large geom) my programs memory usage jumps by about 100megs, eventually causing a crash. Why would this be? I’m not adding any data.

The code is below. Worldlayer is a list of segments of rock, which are described a tuples reading (color, startangle, endangle). defaultLayerVertList is a list of precomputed vertices describing a pairs of vertices around the perimeter of a circle, described a tuples reading (bottomx, bottomz, topx, topz). NumSegments is the number of quads in the circle, and theta segment is what slice of an angle each quad takes up. Quads are composed of 2 triangles, described elsewhere in a triangles prim. rB and rC are the radius of the planet at the base and top of the layer. These are used for calculating the positions of the vertices that do not fall in the default position, eg, the vertices that occur at the boundry between to types of rock, which is arbitrary.

```
def snapToWorldLayer(self, worldLayer, defaultLayerVertList, numSegments, thetaSegment, rB, rC):
worldArcNum = 0
currentWorldArc = worldLayer[worldArcNum]
vdata = self.arc.modifyVertexData()
vertex = GeomVertexWriter(vdata, 'vertex')
color = GeomVertexWriter(vdata, 'color')
vertex.setRow(0)
color.setRow(0)
for i in range (0, numSegments-1):
startPairTheta = i * thetaSegment
endPairTheta = (i+1) * thetaSegment
startPair = defaultLayerVertList[i]
endPair = defaultLayerVertList[i+1]
#If the vertex pair is near the boundry of an arc of rock, move the pair
#from the default position in the defaultLayerVertList, to the position
#of the change in rock type
if startPairTheta-currentWorldArc[1] < (thetaSegment):
boundryTheta = currentWorldArc[1]
xbot = rB*math.cos(boundryTheta)
zbot = rB*math.sin(boundryTheta)
xtop = rC*math.cos(boundryTheta)
ztop = rC*math.sin(boundryTheta)
startPair = (xbot, zbot,xtop,ztop)
if endPairTheta > currentWorldArc[2]:
boundryTheta = currentWorldArc[2]
xbot = rB*math.cos(boundryTheta)
zbot = rB*math.sin(boundryTheta)
xtop = rC*math.cos(boundryTheta)
ztop = rC*math.sin(boundryTheta)
endPair = (xbot, zbot,xtop,ztop)
#Set the verts to the new position
vertex.setData3f(startPair[0], 10, startPair[1])
vertex.setData3f(startPair[2], 10, startPair[3])
vertex.setData3f(endPair[0], 10, endPair[1])
color.setData4f(currentWorldArc[0],0.0,0.0,1.0)
color.setData4f(currentWorldArc[0],0.0,0.0,1.0)
color.setData4f(currentWorldArc[0],0.0,0.0,1.0)
#Add upper right triangle of segment
vertex.setData3f(endPair[2], 10, endPair[3])
vertex.setData3f(endPair[0], 10, endPair[1])
vertex.setData3f(startPair[2], 10, startPair[3])
color.setData4f(currentWorldArc[0],0.0,0.0,1.0)
color.setData4f(currentWorldArc[0],0.0,0.0,1.0)
color.setData4f(currentWorldArc[0],0.0,0.0,1.0)
if endPairTheta > currentWorldArc[2]:
worldArcNum+=1
if worldArcNum > len(worldLayer)-1:
worldArcNum = len(worldLayer)-1
currentWorldArc = worldLayer[worldArcNum]
#The last quad stretches from the last segment to the first segment
currentWorldArc = worldLayer[len(worldLayer)-1]
vertex.setData3f(defaultLayerVertList[numSegments-1][0], 10, defaultLayerVertList[numSegments-1][1])
vertex.setData3f(defaultLayerVertList[numSegments-1][2], 10, defaultLayerVertList[numSegments-1][3])
vertex.setData3f(defaultLayerVertList[0][0], 10, defaultLayerVertList[0][1])
color.setData4f(currentWorldArc[0],0.0,0.0,1.0)
color.setData4f(currentWorldArc[0],0.0,0.0,1.0)
color.setData4f(currentWorldArc[0],0.0,0.0,1.0)
vertex.setData3f(defaultLayerVertList[0][2], 10, defaultLayerVertList[0][3])
vertex.setData3f(defaultLayerVertList[0][0], 10, defaultLayerVertList[0][1])
vertex.setData3f(defaultLayerVertList[numSegments-1][2], 10, defaultLayerVertList[numSegments-1][3])
color.setData4f(currentWorldArc[0],0.0,0.0,1.0)
color.setData4f(currentWorldArc[0],0.0,0.0,1.0)
color.setData4f(currentWorldArc[0],0.0,0.0,1.0)
```