Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

RPi Zero: Crash in adafruit-circuitpython-display-text
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

RPi Zero: Crash in adafruit-circuitpython-display-text

by ronfischler on Fri Aug 21, 2020 12:49 pm

This morning I updated this library from v2.7.10 to v2.8.2 using pip3. Previously I was able to change the font in an existing text area to display on my TFT; now doing so causes a crash:

Traceback (most recent call last):
File "code.py", line 68, in <module>
TFT = DEV_TFT(spi_tft, cs=board.D18, dc=board.D5, driver=ST7789, baudrate=32000000)
File "/home/pi/tools.py", line 519, in __init__
self.set_display_group(0, font=self.default_font, scale=2, x=10, y=120, text="Booting...")
File "/home/pi/tools.py", line 552, in set_display_group
self.text_group[i].font = font
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_display_text/label.py", line 369, in font
self._update_text(str(old_text))
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_display_text/label.py", line 242, in _update_text
self._font.load_glyphs(new_text + "M")
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_bitmap_font/bdf.py", line 100, in load_glyphs
for code_point in remaining:
RuntimeError: Set changed size during iteration


I had originally created this text area using the built-in terminalio.FONT, and then later I change it to a .bdf font I have loaded from the Micro-SD card. This change is no longer accepted. I am hoping this can be fixed.

I have been loading font glyphs using from adafruit_bitmap_font.bitmap_font() before using the font, so I commented that out of my code, and when I run now, I get a slightly different crash:

Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_display_text/label.py", line 352, in text
self._update_text(str(new_text))
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_display_text/label.py", line 242, in _update_text
self._font.load_glyphs(new_text + "M")
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_bitmap_font/bdf.py", line 100, in load_glyphs
for code_point in remaining:
RuntimeError: Set changed size during iteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "code.py", line 68, in <module>
TFT = DEV_TFT(spi_tft, cs=board.D18, dc=board.D5, driver=ST7789, baudrate=32000000)
File "/home/pi/tools.py", line 519, in __init__
self.set_display_group(0, font=self.default_font, scale=2, x=10, y=120, text="Booting...")
File "/home/pi/tools.py", line 568, in set_display_group
self.text_group[i].text = text
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_display_text/label.py", line 355, in text
raise RuntimeError("Text length exceeds max_glyphs")
RuntimeError: Text length exceeds max_glyphs


I note that I had set max_glyphs to 30, so I am not exceeding this limit as suggested in the traceback. This second example that I provided might be a distraction to the overlying issue however, that being: "Set changed size during iteration."

ronfischler
 
Posts: 27
Joined: Thu Jul 23, 2020 3:15 pm

Re: RPi Zero: Crash in adafruit-circuitpython-display-text

by ronfischler on Fri Aug 21, 2020 2:31 pm

While attempting to work around this problem, I discovered it is a bit more serious than I first realized: I can no longer create a text area for my TFT using a loaded .bdf font. It only works now with the built-in terminalio.FONT. I am stuck.

ronfischler
 
Posts: 27
Joined: Thu Jul 23, 2020 3:15 pm

Re: RPi Zero: Crash in adafruit-circuitpython-display-text

by ronfischler on Sat Aug 22, 2020 10:54 am

I reverted the adafruit-circuitpython-display-text package back to version 2.7.10 and this issue went away, and I can load and display custom .bdf fonts on my 2" TFT again. When I have time later today, I will try one update at a time, to discover at what version this breaks.

ronfischler
 
Posts: 27
Joined: Thu Jul 23, 2020 3:15 pm

Re: RPi Zero: Crash in adafruit-circuitpython-display-text

by ronfischler on Tue Aug 25, 2020 12:56 am

I tested various versions of adafruit-circuitpython-display-text, and the last version that works on the RPi Zero board is v2.8.0. I tested the latest version, (put up earlier today?) v2.8.3, and it produces the same failure when trying to use a custom .bdf font:

Debug: loading default font [fonts/ter-u28b.bdf]
Traceback (most recent call last):
File "code.py", line 68, in <module>
TFT = DEV_TFT(spi_tft, cs=board.D18, dc=board.D5, driver=ST7789, baudrate=32000000)
File "/home/pi/tools.py", line 520, in __init__
self.add_text_area(font=self.default_font, text="Booting...", scale=1, color=0xFFFFFF, x=10, y=120, max_glyphs=30)
File "/home/pi/tools.py", line 538, in add_text_area
text_area = label.Label(font, text=text, max_glyphs=max_glyphs)
File "/home/pi/.local/lib/python3.8/site-packages/adafruit_display_text/label.py", line 126, in __init__
self._update_text(str(text))
File "/home/pi/.local/lib/python3.8/site-packages/adafruit_display_text/label.py", line 237, in _update_text
self._font.load_glyphs(new_text + "M")
File "/home/pi/.local/lib/python3.8/site-packages/adafruit_bitmap_font/bdf.py", line 100, in load_glyphs
for code_point in remaining:
RuntimeError: Set changed size during iteration


So, the problem appears to be in label.Label() on the Rpi Zero. I looked at that earlier and I did not understand what is going on there, but I will look at it again.

ronfischler
 
Posts: 27
Joined: Thu Jul 23, 2020 3:15 pm

Re: RPi Zero: Crash in adafruit-circuitpython-display-text

by ronfischler on Wed Sep 02, 2020 2:06 pm

I have an update for this issue.

Firstly, I made a mistake for the title "RPi Zero: Crash in adafruit-circuitpython-display-text" - I apologize for doing this. The crash occurs in a module called by display-text: adafruit_bitmap_font/bdf.py (version 1.2.0) line 100.

This code in bdf.py looks like:
Code: Select all | TOGGLE FULL SIZE
for code_point in remaining:
            if code_point in self._glyphs and self._glyphs[code_point]:
                remaining.remove(code_point)


I found that this is not difficult to fix, simply use copy() to iterate over a copy of the set, while removing items from the original. I learned this from reading a post here: https://stackoverflow.com/questions/228 ... ntimeerror

So, the updated code would look like this:
Code: Select all | TOGGLE FULL SIZE
for code_point in remaining.copy():
            if code_point in self._glyphs and self._glyphs[code_point]:
                remaining.remove(code_point)


I tested this on my RPi Zero, and it works! Problem solved. I am hoping that Adafruit can update bdf.py with this change.

ronfischler
 
Posts: 27
Joined: Thu Jul 23, 2020 3:15 pm

Re: RPi Zero: Crash in adafruit-circuitpython-display-text

by tannewt on Wed Sep 02, 2020 2:18 pm

Nice find Ron! Would you mind making a Pull Request to the library with the fix?

This guide is a good reference for the process: https://learn.adafruit.com/contribute-t ... and-github

tannewt
 
Posts: 1784
Joined: Thu Oct 06, 2016 8:48 pm

Re: RPi Zero: Crash in adafruit-circuitpython-display-text

by ronfischler on Wed Sep 02, 2020 2:26 pm

tannewt wrote:Nice find Ron! Would you mind making a Pull Request to the library with the fix?

This guide is a good reference for the process: https://learn.adafruit.com/contribute-t ... and-github


Thank you for your response! I will read the guide and try to make the change myself.

ronfischler
 
Posts: 27
Joined: Thu Jul 23, 2020 3:15 pm

Re: RPi Zero: Crash in adafruit-circuitpython-display-text

by ronfischler on Wed Sep 02, 2020 3:38 pm

Hi Tannewt,

I read the guide you recommended, (nicely written by the way,) followed the directions, made my update to bdf.py, and finished by making my first Pull Request on Github. I note that the check done by PyLint failed, not sure what to do about that.

ronfischler
 
Posts: 27
Joined: Thu Jul 23, 2020 3:15 pm

Re: RPi Zero: Crash in adafruit-circuitpython-display-text

by tannewt on Wed Sep 02, 2020 6:43 pm

Thanks! I'll follow up on the PR.

Link for folks following along: https://github.com/adafruit/Adafruit_Ci ... nt/pull/28

tannewt
 
Posts: 1784
Joined: Thu Oct 06, 2016 8:48 pm

Please be positive and constructive with your questions and comments.