That did the trick!
I think we've all been bitten by "is" vs "==" before, so that's great it
was an easy fix.
I'm also happy to report that this also fixes the unstable animation speed
issue. As it turns out, the animation speed was always fine. What I was
seeing was multiple animations being added on top of one another, and
running in parallel interleaved.
Now that this is fixed, shall we merge it in?
On Tuesday, February 21, 2017 at 2:59:57 PM UTC+9, Leif Theden wrote:
>
> Thank you brad for the detailed comments and the test code. I was able to
> isolate the problem to the "is" operator not properly identifying bound
> methods of sprite objects (likely, or any other bound method for that
> matter). Because it was not properly id'ing function passed to
> Clock.unschedule, they were not being removed. It seems that "is" will not
> work, but a simple equality check will. Unit tests seem to work well.
>
> You'll notice that your test code will still report 2 scheduled items in
> the queue. Note the comments in the unschedule method; items are not
> removed right away in the event that there are several unscheduled
> functions at once and causing excessive heap activity. They remain in the
> queue until they are checked again then removed without processing
> callbacks.
>
>
> On Monday, February 20, 2017 at 8:20:13 PM UTC-6, Benjamin Moran wrote:
>>
>> Leif,
>>
>> I put together a quick example. While it doesn't crash, It does
>> illustrate what may be the root cause: animations are not being
>> unscheduled properly. When changing a sprite's img/animation, it will call
>> clock.unschedule(). The print function in the example code shows that the
>> list of scheduled functions keeps growing every time you change one. Hope
>> this helps!
>>
>> (It would be a lot cleaner to use a proper animation, but I just mocked
>> this up using transforms of the included png in the pyglet repo)
>>
>> import pyglet
>>
>> window = pyglet.window.Window()
>> batch = pyglet.graphics.Batch()
>>
>> image = pyglet.image.load("examples/pyglet.png")
>> image.anchor_x = image.width//2
>> image.anchor_y = image.height//2
>>
>> frames = []
>> for i in range(4):
>> angle = i * 90 % 360
>> img = image.texture.get_transform(rotate=angle)
>> frames.append(img)
>> ani = pyglet.image.Animation.from_image_sequence(frames, 0.08)
>> ani2 = pyglet.image.Animation.from_image_sequence(frames, 0.2)
>>
>> sprite = pyglet.sprite.Sprite(ani, x=window.width//2, y=window.height//2,
>> batch=batch)
>>
>>
>> @window.event
>> def on_key_press(key, mod):
>> if key == pyglet.window.key.SPACE:
>> sprite.image = ani2
>> print(pyglet.clock.get_default()._schedule_interval_items)
>>
>>
>> @window.event
>> def on_draw():
>> window.clear()
>> batch.draw()
>>
>>
>> if __name__ == "__main__":
>> pyglet.app.run()
>>
>>
>>
>>
>> On Tuesday, February 21, 2017 at 1:25:11 AM UTC+9, Leif Theden wrote:
>>>
>>> I wrote the experimental clock. Thanks for the input. I realize I've
>>> been silent for a long time, but with some details about the issues, I can
>>> work towards better compatibility.
>>>
>>> Leif
>>>
>>> On Mon, Feb 20, 2017 at 7:09 AM, Benjamin Moran <[email protected]>
>>> wrote:
>>>
>>>> I've actually come across some issues myself, so this will need some
>>>> additional work before merging. The first is a fairly consistent crash
>>>> when changing a sprite's animation. The second is that the animation speed
>>>> is not consistent. It's off enough to be visually obvious, so it should be
>>>> tweaked a bit.
>>>>
>>>> --
>>>> You received this message because you are subscribed to a topic in the
>>>> Google Groups "pyglet-users" group.
>>>> To unsubscribe from this topic, visit
>>>> https://groups.google.com/d/topic/pyglet-users/_0eLxtKfUy4/unsubscribe.
>>>> To unsubscribe from this group and all its topics, send an email to
>>>> [email protected].
>>>> To post to this group, send email to [email protected].
>>>> Visit this group at https://groups.google.com/group/pyglet-users.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.