Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crash changing Label color #45

Closed
ccanepa opened this issue Aug 20, 2019 · 5 comments
Closed

crash changing Label color #45

ccanepa opened this issue Aug 20, 2019 · 5 comments

Comments

@ccanepa
Copy link
Contributor

ccanepa commented Aug 20, 2019

Hi Ben.

The fix to #40, traceback while changing HTMLLabel color, broke the same thing for Label

Repro: take the HTML bugdemo, replace HTMLLabel with Label, run.

I got the traceback

(py37-cocos) E:\dev\cocos_2019_extras>python _pyglet_label_color.py
Traceback (most recent call last):
  File "_pyglet_label_color.py", line 29, in <module>
    pyglet.app.run()
  File "e:\dev\pyglet-2019\pyglet\app\__init__.py", line 144, in run
    event_loop.run()
  File "e:\dev\pyglet-2019\pyglet\app\base.py", line 175, in run
    self._run()
  File "e:\dev\pyglet-2019\pyglet\app\base.py", line 187, in _run
    timeout = self.idle()
  File "e:\dev\pyglet-2019\pyglet\app\base.py", line 308, in idle
    redraw_all = self.clock.call_scheduled_functions(dt)
  File "e:\dev\pyglet-2019\pyglet\clock.py", line 333, in call_scheduled_functio
ns
    item.func(now - item.last_ts, *item.args, **item.kwargs)
  File "_pyglet_label_color.py", line 25, in update
    hlabel.color = tuple(color[:3]) + (opacity,)
  File "e:\dev\pyglet-2019\pyglet\text\__init__.py", line 309, in color
    {'color': color})
  File "e:\dev\pyglet-2019\pyglet\text\document.py", line 604, in set_style
    0, len(self.text), attributes)
  File "e:\dev\pyglet-2019\pyglet\text\document.py", line 512, in set_style
    self.dispatch_event('on_style_text', start, end, attributes)
  File "e:\dev\pyglet-2019\pyglet\event.py", line 400, in dispatch_event
    if handler(*args):
  File "e:\dev\pyglet-2019\pyglet\text\layout.py", line 1062, in on_style_text
    self._update_color()
  File "e:\dev\pyglet-2019\pyglet\text\layout.py", line 977, in _update_color
    for start, end, color in colors_iter.ranges(0, colors_iter.end):
AttributeError: 'ConstRunIterator' object has no attribute 'end'

win 7-64, python 3.7

pyglet
from github master
commit ebe94a0
Date: Fri Aug 16 16:55:35 2019 +0900
Tweaked Travis-CI due to OSX breakage.

In cocos I will track both problems in the same issue, los-cocos/cocos#322

@ccanepa
Copy link
Contributor Author

ccanepa commented Aug 20, 2019

Not a fix, this reverts to the situation in #40

The problem manifests around layout line 977, but comes from elsewere.

Just before 977 put two lines

        print(" >>>> type(colors_iter):", type(colors_iter))
        raise RuntimeException

running the two bugdemos (I used the cocos ones, you can use the pyglet ones) I got

(py37-cocos) E:\dev\cocos2019\test>python test_htmllabel_opacity.py
 >>>> type(colors_iter): <class 'pyglet.text.runlist.RunIterator'>
[irrelevant long traceback] 

 (py37-cocos) E:\dev\cocos2019\test>python test_label_changing.py
 >>>> type(colors_iter): <class 'pyglet.text.runlist.ConstRunIterator'>
[irrelevant long traceback]

The problem is that both pyglet classes
class 'pyglet.text.runlist.ConstRunIterator' and 'pyglet.text.runlist.RunIterator' should present the same API to line 977, and they are not.

@benmoran56
Copy link
Member

Thanks for digging into this Claudio, I'll see if I can fix this up a bit later.

@benmoran56
Copy link
Member

I think a simple way to fix the issue would be to add self.end = length to the ConstRunIterator. All other iterators use this syntax, so we can consolidate on end.

If you have a moment, could you see if that would fix it? We would also want to change the .length attributes back to .end in the text.layout as well.

@ccanepa
Copy link
Contributor Author

ccanepa commented Aug 21, 2019

With the suggested change (add self.end = length in ConstRunIterator and write line 977 in the .end styles) both scripts don't traceback, and seems to work as expected (visual apreciation)

@benmoran56
Copy link
Member

Thanks Claudio, I'll push this in today. I think we can get a new point release out soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants