Skip to content

Fruit Jam -- OnDiskFont() fails with a "MemoryError: memory allocation failed, allocating 0 bytes" error #10560

@ukscone

Description

@ukscone

CircuitPython version and board name

Adafruit CircuitPython 10.0.0-beta.2 on 2025-07-30; Adafruit Fruit Jam with rp2350b

Code/REPL

# SPDX-FileCopyrightText: Copyright (c) 2025 Tim C for Adafruit Industries
# SPDX-FileCopyrightText: Copyright (c) 2025 Anne Barela for Adafruit Industries
#
# SPDX-License-Identifier: MIT
#
import gc

from terminalio import Terminal
import displayio 
from lvfontio import OnDiskFont
from adafruit_fruitjam.peripherals import request_display_config
import supervisor

def draw_box(width, height, color_box, x, y):
#    top_left = '\xDA'  # CP437 characters for single line drawing
#    horizontal = '\xC4'
#    top_right = '\xBF'
#    vertical = '\xB3'
#    bottom_left = '\xC0'
#    bottom_right = '\xD9'
    top_left = '+'  # ASCII characters if the CP437 characters aren't working
    horizontal = '-'
    top_right = '+'
    vertical = '|'
    bottom_left = '+'
    bottom_right = '+'
    if width < 3 or height < 3:
        return
    goto(x, y)
    terminal.write(top_left + horizontal*(width - 2) + top_right+"\x1BD")
    for i in range(height):
        goto(x+i+1, y)
        terminal.write(vertical + ' '*(width - 2) + vertical+"\x1BD")
    goto(x+height, y)
    terminal.write(bottom_left+horizontal*(width - 2)+bottom_right+"\x1BD") 
  
def goto(x, y):
    seq = "\x1B[" + str(int(x)) + ";" + str(int(y)) + "H"
    terminal.write(seq)

# Use the easy library call to set the resolution

colors = 2

request_display_config(640, 480)

print(f"\nFree before display init: {gc.mem_free()}")

# Initialize display

main_group = displayio.Group()
display = supervisor.runtime.display
display.root_group = main_group

print(f"free: {gc.mem_free()}")

font = OnDiskFont("fonts/CamputersLynxAlt.bin")  # LVGL .bin font

char_size = font.get_bounding_box()
print(f"Character size: {char_size}")
screen_size = (display.width // char_size[0], display.height // char_size[1])
print(f"Screen size: {screen_size}")

terminal_palette = displayio.Palette(colors)
terminal_palette[0] = 0x000000
terminal_palette[1] = 0xffffff

print(f"Free after palette: {gc.mem_free()}")

term_bitmap = displayio.Bitmap(screen_size[0] * char_size[0], 
                               screen_size[1] * char_size[1], colors)
print(f"Free after bitmap: {gc.mem_free()}")   

terminal_area = displayio.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)

print("About to create Terminal")
terminal = Terminal(terminal_area, font)
print("Created Terminal")
message = " Hello World\n This is LVGL text\r\n"
terminal.write(message)
print("Wrote message, now do a box")
terminal.write("\x1B[r")  # Set to whole screen (ineffective)
draw_box(10, 8, 1, 10, 25)

print("Done, infinite loop")
while True:
    pass

Behavior

%Run -c $EDITOR_CONTENT

Free before display init: 8093152
free: 8092928
Traceback (most recent call last):
File "", line 57, in
MemoryError: memory allocation failed, allocating 0 bytes

Description

Fairly regularly (60 times out of 100) both with the above code and with a modded https://learn.adafruit.com/fruit-jam-irc-client-in-circuitpython?view=all OnDiskFont() will fail with the above error message on the fonts noted in the additional information section. the lvgl bin fonts CamputersLynxStd & CamputersLynxAlt were created from the ttf files using https://lvgl.io/tools/fontconverter with the settings size 10, bpp 1, no fallback, output binary, range 0x20-0x7F. Sometimes the CamputersLynxAlt font produces a "missing glyph" error

The memory allocation error happens whether the Fruit Jam is freshly powered, after reset and in thonny repl. I fully expect that the fonts are corrupted somehow but it does seem regularly random

Additional information

I have uploaded the problematic lvgl converted ttf's and bins to https://eightgrubs.com/Files/

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions