adafruit / adafruit/Adafruit_CircuitPython_Bitmap_Font
lvfontbin behaves different as .mpy and .py
- Dominant language
- Python
- Stars
- 35
- Forks
- 24
- PR merge metrics
- No merged PRs in 30d
Description
```
Adafruit CircuitPython 10.0.0-alpha.7-5-g203c9990e6-dirty on 2025-06-25; Adafruit Fruit Jam with rp2350b
```
With this code:
```
import gc
from displayio import Group, TileGrid, Palette
from terminalio import Terminal, FONT
from adafruit_bitmap_font import bitmap_font
import supervisor
main_group = Group()
display = supervisor.runtime.display
display.root_group = main_group
print(f"free: {gc.mem_free()}")
# font = FONT
font = bitmap_font.load_font("fonts/terminal.lvfontbin")
char_size = font.get_bounding_box()
print(f"char_size: {char_size}")
screen_size = (display.width // char_size[0], display.height // char_size[1])
terminal_palette = Palette(2)
terminal_palette[0] = 0x000000
terminal_palette[1] = 0xffffff
terminal_area = TileGrid(bitmap=font.bitmap, width=screen_size[0], height=screen_size[1],
tile_width=char_size[0], tile_height=char_size[1], pixel_shader=terminal_palette)
main_group.append(terminal_area)
terminal = Terminal(terminal_area, font)
message = f"Hello World"
terminal.write(message)
while True:
pass
```
when `adafruit_bitmap_font` is mpy files:
```
code.py output:
free: 8262784
Traceback (most recent call last):
File "code.py", line 15, in
File "adafruit_bitmap_font/bitmap_font.py", line 71, in load_font
File "adafruit_bitmap_font/lvfontbin.py", line 77, in __init__
MemoryError: memory allocation failed, allocating 28161 bytes
```
and when `adafruit_bitmap_font` is py files instead:
```
code.py output:
free: 8262768
char_size: (0, 16, 0, -4)
Traceback (most recent call last):
File "code.py", line 18, in
ZeroDivisionError: division by zero
```
The divide by zero error I think is unrelated to the difference in behavior between mpy and py, it seems to be due to lvfont having different values for bounding box than the code I am using had expected.
This issue is specifically for the fact that `load_font()` raises memory error when run as .mpy files but suceeds when run as .py files.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.