Description
Tested on pyportal titano with adafruit-circuitpython-pyportal_titano-en_US-20250428-main-PR10288-1e4d766.uf2
using this reproducer code
import time
import supervisor
from displayio import Palette
from tilepalettemapper import TilePaletteMapper
import board
import terminalio
import displayio
display = supervisor.runtime.display
time.sleep(1)
p = Palette(8)
p[0] = 0x000000
p[1] = 0xffffff
bbox = terminalio.FONT.get_bounding_box()
main_group = displayio.Group()
display.root_group = main_group
tpm = TilePaletteMapper(p, 2, 10,4)
tg = displayio.TileGrid(terminalio.FONT.bitmap, pixel_shader=tpm,
tile_width=bbox[0], tile_height=bbox[1],
width=10, height=4, default_tile=0)
main_group.append(tg)
for i in range(40):
tg[i] = i
while True:
for y in range(tg.height):
for x in range(tg.width):
cur = (x, y)
tpm[cur] = [1,0] if tpm[cur] == (0,1) else [0,1]
print(f"{cur}, {tpm[cur]}")
time.sleep(0.025)
I think there is something wonky going on with the memory that TilePaletteMapper is using internally to store the list of mappings. The first iteration seems to run normally the tiles in the grid get set to white background.
All iterations after the first start getting wonky, instead of simply alternating the colors as the code should it starts erratically changing the color mapping of each tile, some tiles seem to end up with [0, 0]
causing them to appear "invisible".
After a handful of iterations the code crashes with this exception:
Traceback (most recent call last):
File "code.py", line 43, in <module>
TypeError: object '' isn't a tuple or list
which points to the line print(f"{cur}, {tpm[cur]}")
but I don't understand what the error means or why it comes up after several iterations seemingly randomly. I believe that as the mappings are getting set it's actually clobbering other memory and eventually overwrites something important that ends up leading to this error.
Not with this exact reproducer code, but with similar TPM manipulations I had a hard fault memory error occur a few times as well which also leads me to the suspicion that something wonky is happening with the internal memory in use by TPM.
Running the exact same code on 9.2.7
and 10.0.0-alpha.2
results in the expected behavior of black / white colors alternating with each iteration.