From: Wojtek F. <woj...@gm...> - 2011-07-22 09:16:14
|
Hi! I'm new to VPython project but I found a memory leak. There was something mentioned about this problem before. I found it here: http://sourceforge.net/mailarchive/forum.php?thread_name=AANLkTim8RL8kjW0%3DSK%2B9f-2A5TCQv6wAu9aTpBmisbNS%40mail.gmail.com&forum_name=visualpython-users. But unfortunately I didn't find the solution. I want to use VPython to render a surface which is beeing changed during the program execution. To show you what I'm talking about I changed one of the example programs (faces_heighfield.py). Now it looks something like this: <code> from visual import * class Model: def __init__(self): self.frame = frame() self.model = faces(frame=self.frame, color=color.cyan) self.vertices = [] def FacetedTriangle(self, v1, v2, v3, color=color.white): """Add a triangle to the model""" for v in (v1,v2,v3): self.vertices.append(v) def FacetedPolygon(self, *v): """Appends a planar polygon of any number of vertices to the model""" for t in range(len(v)-2): self.FacetedTriangle( v[0], v[t+1], v[t+2] ) class Mesh (Model): def __init__(self): Model.__init__(self) def Draw(self, xvalues, yvalues, zvalues): points = zeros( xvalues.shape + (3,), float ) points[...,0] = xvalues points[...,1] = yvalues points[...,2] = zvalues self.vertices = [] for i in range(zvalues.shape[0]-1): for j in range(zvalues.shape[1]-1): self.FacetedPolygon( points[i,j], points[i,j+1], points[i+1,j+1], points[i+1,j] ) self.model.pos = self.vertices self.model.make_normals() self.model.smooth() self.model.make_twosided() x = arange(-1,1,2./20) y = arange(-1,1,2./20) z = zeros( (len(x),len(y)), float ) x,y = x[:,None]+z, y+z m = Mesh() i = 0 dt = 0.1 while True: m.Draw( x, (sin(x*pi + i*dt)+sin(y*pi + i*dt))*0.2, y ) i += 1 rate(10) </code> When running this code we see quite a nice surface movement. That is what I need. But the memory usage grows infinitely! My question is... is there any fix for this memory leak? Or do you know other way to achieve similar visual effect in VPython? I also tried to render the surface using convexes or points instead of faces but the memory leak always existed... Thanks in advance for your help. Greetings, Wojciech Frycz |