adafruit / Adafruit_CircuitPython_framebuf

CircuitPython framebuf module, based on the Python framebuf module
MIT License
39 stars 36 forks source link

Integer overflow when using text() on non-Express boards #25

Closed mitsake closed 5 years ago

mitsake commented 5 years ago

I've been working with CircuitPython on a Trinket M0-based board, and I'm currently unable to use text() to write to the screen. I get the following error:

Traceback (most recent call last):
  File "code.py", line 34, in <module>
  File "adafruit_framebuf.py", line 344, in text
  File "adafruit_framebuf.py", line 404, in __init__
OverflowError: small int overflow

I think the culprit is the file size check added in commit b7c793787afaf6f355cf55a4dd5b1e48fc0656ca. os.stat() can return integers larger than non-Express boards support (particularly st_mtime, and friends), which then causes an error when attempting to load the font file.

I'm trying to work out an alternative way to determine file size, and if I come across one will try to submit a pull request.

ladyada commented 5 years ago

just to check , what version are you running on trinket m0 of circuitpython?

mitsake commented 5 years ago

Sorry, should have included that! I'm running 4.1.0.

ladyada commented 5 years ago

wanna try 5.0? just in case...

mitsake commented 5 years ago

Just upgraded (libraries too), and got the same error I'm afraid.

ladyada commented 5 years ago

@caternuson wanna take a stab at this?

caternuson commented 5 years ago

Sure, can take a look. @mitsake Can you give me a simple code.py that I can use for testing?

mitsake commented 5 years ago

Of course - the following code.py produces the error for me:

import board
import busio
import adafruit_ssd1306

i2c = busio.I2C(board.SCL, board.SDA)
oled = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)

oled.text("Hello world!", 0, 0, 1)
oled.show()

The error can be replicated without the framebuf library:

import os
os.stat('code.py') # can be any file that's present on the drive

As a result, I'm not sure if this issue belongs here, or in the core CircuitPython repo? Apologies if I've put it in the wrong place - this is my first time reporting something!

caternuson commented 5 years ago

@mitsake Thanks for the example. @ladyada This might be a core issue?

Adafruit CircuitPython 4.1.0 on 2019-08-02; Adafruit Trinket M0 with samd21e18
>>> import os
>>> os.stat("/font5x8.bin")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: small int overflow
>>> 

EDIT 5.0 alpha 4 FWIW:

Adafruit CircuitPython 5.0.0-alpha.4 on 2019-09-15; Adafruit Trinket M0 with samd21e18
>>> import os
>>> os.stat("/font5x8.bin")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: small int overflow
>>> 
ladyada commented 5 years ago

ahh yeah small non-express boards do not have long int support :( can we work around it somehow?

mauriciobenjamin commented 5 years ago

By the way... also the Feather M0 Adalogger samd21g18 have the same issue. Of course, it's a non-express board.

caternuson commented 5 years ago

Could add a try/except? The usage is just a sanity check: https://github.com/adafruit/Adafruit_CircuitPython_framebuf/blob/c22eca93045aa9090b46f075be817f3f0ef32f82/adafruit_framebuf.py#L403-L405 And just give up in the except and hope for the best. If the file is not valid, just let it break elsewhere.

Or is this something worth changing in CP?

ladyada commented 5 years ago

yah try/except is probably ok. im not actually sure framebuf/oled will work on a trinket m0 at all :D

caternuson commented 5 years ago

can at least get as far as hello world :) oled_test

ladyada commented 5 years ago

yay looks good

caternuson commented 5 years ago

@mitsake Please try the 1.2.1 release when it becomes available: https://github.com/adafruit/Adafruit_CircuitPython_framebuf/releases/tag/1.2.1

mitsake commented 5 years ago

IMG_8776 2 Seems to work fine for me! Thanks very much - do I close the issue, or do you?

ladyada commented 5 years ago

nice!