On Tue, Aug 26, 2008 at 5:40 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> hello,
>
> I'm trying to load textures in loop at an average of 1 fps. It
> appears every iteration of the loop the image/texture data isn't
> being
> garbage collected and the script dies within a few minutes of a memory
> error. Has anyone else encountered this leak? Is there
> a better way to do this? It needs to be scalable so loading all the
> images in at the start is not an option.
>
> I've tried to explicitly reassign the self.img variable by setting it
> to None and del self.img along with several other attempts. Any
> ideas?
>
> thanks, mark
>
>
> from __future__ import division
> from math import pi, sin, cos
> from numpy import *
> from pyglet import image
> from pyglet.gl import *
> from pyglet import *
> from pyglet import clock
> from pyglet import window
> from pyglet.window import key
> import pyglet
> import random
> import glob, os, sys
> import gc
>
> try:
> # Try and create a window with multisampling (antialiasing)
> config = Config(sample_buffers=1, samples=4, double_buffer=True,)
> #depth_size=16,
> w = window.Window(resizable=True, config=config)
>
> except window.NoSuchConfigException:
> # Fall back to no multisampling for old hardware
> w = window.Window(resizable=True)
>
> def setup():
> # One-time GL setup
> glClearColor(0, 0, 0, 1)
> glDisable(GL_DEPTH_TEST)
> glEnable(GL_LIGHT0)
> glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
> glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
> glEnable(player.img.target)
> glBindTexture(player.img.target, player.img.id)
>
>
> @w.event
> def on_resize(width, height):
> # Override the default on_resize handler to create a 3D projection
> glViewport(0, 0, width, height)
> glMatrixMode(GL_PROJECTION)
> glLoadIdentity()
> gluPerspective(60., float(width) / float(height), .1, 1000.)
> glMatrixMode(GL_MODELVIEW)
> glClearColor(0, 0, 0, 1)
> glDisable(GL_DEPTH_TEST)
> glEnable(GL_LIGHT0)
> glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
> glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
> glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
> return pyglet.event.EVENT_HANDLED
>
>
> pyglet.resource.path = ['images']
> pyglet.resource.reindex()
>
> class Player():
> def __init__(self):
> self.images = ['image.png','image2.png','image3.png']
> self.x = 0
> self.img = image.load(self.images[0]).get_texture()
>
> def new_img(self,dt):
> self.x += 1
> self.img = image.load(self.images[self.x%3]).get_texture()
>
You could preload all your textures in __init__() and then iterate
over them in new_img(). For example:
def __init__(self):
self.images = itertools.cycle([image.load(img).get_texture()
for img in ['image1.png', 'image2.png',
'image3.png']])
self.img = self.images.next()
def new_img(self, dt):
...
self.img = self.images.next()
However, the problem is really already solved for your by pyglet.
There are better ways to do what you're trying described here:
http://pyglet.org/doc/programming_guide/image_sequences_and_atlases.html
http://pyglet.org/doc/programming_guide/animations.html
--
\\\\\/\"/\\\\\\\\\\\
\\\\/ // //\/\\\\\\\
\\\/ \\// /\ \/\\\\
\\/ /\/ / /\/ /\ \\\
\/ / /\/ /\ /\\\ \\
/ /\\\ /\\\ \\\\\/\
\/\\\\\/\\\\\/\\\\\\
d.p.s
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---