Thread: [PyOpenGL-Users] glInterleavedArrays memory leak
Brought to you by:
mcfletch
From: Micah D. <mi...@na...> - 2003-07-23 10:29:44
|
Hi Everybody, I believe I found a memory leak in PyOpenGL's wrapper for glInterleavedArrays. The following is the simplest test case I could come up with: ------8<------ import pygame, time from pygame.locals import * from OpenGL.GL import * pygame.init() pygame.display.set_mode((640,480), OPENGL|DOUBLEBUF) while 1: glInterleavedArrays(GL_T2F_N3F_V3F, 0, " " * 10000) time.sleep(0.01) ------>8------ In 'top' this should show the python process' memory usage steadily rising. This is from a Gentoo Linux system on an Athlon XP. I have tested it with PyOpenGL 2.0.0.42 and 2.0.1.04, both show the bug. As much as I'm interested in helping squash this bug, I'm also interested in finding a workaround so my users (when they exist :) won't absolutely have to have the latest PyOpenGL code. I have tried using glVertexPointer and friends, however glTexCoordPointerf() would always cause an "OpenGL.GL.GLerror: [Errno 1281] invalid value" exception. I'd like to thank the PyOpenGL developers for bringing such a neat interface to life. I have been using it for a 3D frontend to PyBZFlag with amazing results. Most people think Python is too slow for games, then they see what can be accomplished with outstanding modules like PyOpenGL and Numeric :) In case you're curious, I have a few screenshots of what we've done so far: (Yep, there's a realtime cloth simulation in there too) http://navi.picogui.org/images/bzflag/ The code is in BZFlag's CVS repository. --Micah -- Only you can prevent creeping featurism! |
From: Rene D. <il...@ya...> - 2003-08-02 03:01:43
|
Micah Dowty wrote: >Hi Everybody, > >I believe I found a memory leak in PyOpenGL's wrapper for >glInterleavedArrays. The following is the simplest test case I could >come up with: > >------8<------ >import pygame, time >from pygame.locals import * >from OpenGL.GL import * >pygame.init() >pygame.display.set_mode((640,480), OPENGL|DOUBLEBUF) >while 1: > glInterleavedArrays(GL_T2F_N3F_V3F, 0, " " * 10000) > time.sleep(0.01) >------>8------ > >In 'top' this should show the python process' memory usage steadily >rising. This is from a Gentoo Linux system on an Athlon XP. >I have tested it with PyOpenGL 2.0.0.42 and 2.0.1.04, both show the bug. > >As much as I'm interested in helping squash this bug, I'm also >interested in finding a workaround so my users (when they exist :) won't >absolutely have to have the latest PyOpenGL code. > >I have tried using glVertexPointer and friends, however >glTexCoordPointerf() would always cause an "OpenGL.GL.GLerror: [Errno >1281] invalid value" exception. > >I'd like to thank the PyOpenGL developers for bringing such a neat >interface to life. I have been using it for a 3D frontend to PyBZFlag >with amazing results. Most people think Python is too slow for games, >then they see what can be accomplished with outstanding modules like >PyOpenGL and Numeric :) > >In case you're curious, I have a few screenshots of what we've done so >far: (Yep, there's a realtime cloth simulation in there too) > http://navi.picogui.org/images/bzflag/ >The code is in BZFlag's CVS repository. > >--Micah > > > Very nice on the bzFlag front! The memory leak is there. It leaks with numeric arrays as well. #-------------------------------------------------------------------------------------------- import pygame, time from pygame.locals import * from OpenGL.GL import * import Numeric try: from numeric_gl import * except: print "numeric_gl import failed" pygame.init() pygame.display.set_mode((640,480), OPENGL|DOUBLEBUF) while 1: b = [ 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0 ] * (10000 / 12) glInterleavedArrays( GL_V3F, 0, b) time.sleep(0.01) pygame.display.flip() #-------------------------------------------------------------------------------------------- It's related to the way that array related functions in pyopengl are used. I've been thinking of redoing them for a while but haven't had time :( I've made a seperate numeric module with the gl*Pointer functions. I just added a glInterleavedArrays which doesn't seem to have a memory leak. Could you give it a go and tell me what you think? It can be found here: http://py3d.org/files/numeric_gl.tar.gz It only works with numeric arrays(ie strings etc will probably not work). It's only tested/compiled on debian linux. I ran the OpenglContext test which used numeric arrays and it ran ok once I removed the tostring() calls. I will eventually add this into pyopengl I think. That is a seperate sub module for numeric stuff. Which would be automatically detected and included into OpenGL.GL using python. Along with some PyArray_ContiguousFromObject type function calls to allow you to check if memory is being copied unnecessarily(or did you allready add something like this Mike?). Have fun! |
From: Mike C. F. <mcf...@ro...> - 2003-08-02 12:40:45
|
Rene Dudfield wrote: ... > The memory leak is there. It leaks with numeric arrays as well. :( ... > It's related to the way that array related functions in pyopengl are > used. I've been thinking of redoing them for a while but haven't had > time :( The typemaps are definitely the hairiest part of PyOpenGL. I'd really love to rewrite them in a more robust way (was considering producing them with a Python script, rather than the huge numbers of pre-processor macros currently used). What I'd like even more would be a test-suite for the set of type-maps, but that's probably beyond my resources for a good long while. ... > I will eventually add this into pyopengl I think. That is a seperate > sub module for numeric stuff. Which would be automatically detected > and included into OpenGL.GL using python. I'll try to get some time to look at it. Too many projects going simultaneously, and with the new job I really don't have more than a few hours/week to work on the Open Source stuff that isn't related to the job. Probably should wade through the patches and bug-reports that have been piling up first I suppose :) . > Along with some PyArray_ContiguousFromObject type function calls to > allow you to check if memory is being copied unnecessarily(or did you > allready add something like this Mike?). The code currently only copies if there is a type mis-match. However, it would likely be a better strategy to first see if there's a matching function for the given data-type and use that instead of the specified function. i.e. if someone calls gl*Pointerf( ) with a double array, use the gl*Pointerd( ) version rather than converting to 'f' and calling the specified function. Have fun, Mike _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ |
From: Micah D. <mi...@na...> - 2003-08-02 20:36:29
|
On Sat, Aug 02, 2003 at 01:01:20PM +1000, Rene Dudfield wrote: > Micah Dowty wrote: ... > >In 'top' this should show the python process' memory usage steadily > >rising. This is from a Gentoo Linux system on an Athlon XP. > >I have tested it with PyOpenGL 2.0.0.42 and 2.0.1.04, both show the bug. ... > Very nice on the bzFlag front! > > The memory leak is there. It leaks with numeric arrays as well. > > #-------------------------------------------------------------------------------------------- > import pygame, time > from pygame.locals import * > from OpenGL.GL import * > import Numeric > try: > from numeric_gl import * > except: > print "numeric_gl import failed" > > pygame.init() > pygame.display.set_mode((640,480), OPENGL|DOUBLEBUF) > while 1: > b = [ 0.0, 0.0, 0.0, > 1.0, 0.0, 0.0, > 1.0, 1.0, 0.0, > 0.0, 1.0, 0.0 ] * (10000 / 12) > > glInterleavedArrays( GL_V3F, 0, b) > > time.sleep(0.01) > pygame.display.flip() > #-------------------------------------------------------------------------------------------- > > > It's related to the way that array related functions in pyopengl are > used. I've been thinking of redoing them for a while but haven't had > time :( > > I've made a seperate numeric module with the gl*Pointer functions. I > just added a glInterleavedArrays which doesn't seem to have a memory leak. > > Could you give it a go and tell me what you think? > > > It can be found here: > http://py3d.org/files/numeric_gl.tar.gz > > It only works with numeric arrays(ie strings etc will probably not work). > > It's only tested/compiled on debian linux. I ran the OpenglContext test > which used numeric arrays and it ran ok once I removed the tostring() calls. > I'm on Gentoo here with Python 2.2.3 and it compiled fine. Appears to solve the memory leak too :) > > I will eventually add this into pyopengl I think. That is a seperate > sub module for numeric stuff. Which would be automatically detected and > included into OpenGL.GL using python. I'm looking forward to it! > > Along with some PyArray_ContiguousFromObject type function calls to > allow you to check if memory is being copied unnecessarily(or did you > allready add something like this Mike?). > > > Have fun! > > > > > > ------------------------------------------------------- > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > Data Reports, E-commerce, Portals, and Forums are available now. > Download today and enter to win an XBOX or Visual Studio .NET. > http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01 > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users -- Only you can prevent creeping featurism! |