MLB-LED-Scoreboard / mlb-led-scoreboard

An LED scoreboard for Major League Baseball :baseball:
GNU General Public License v3.0
596 stars 105 forks source link

If emoji is present in News Article Title, then python script crashes due to a ZeroDivisionError #463

Closed randolph-gravely closed 1 year ago

randolph-gravely commented 1 year ago

This issue is a

Hardware Configuration

Software Configuration v6.3.0

Expected behavior

Ticker should rotate properly to the next screen

Actual behavior

If emoji is present in an MLB Article, it appears it causes the script to crash (at least in emulation mode). The following error occurs: Emulator/graphics/init.py", line 19, in DrawText adjustment = abs(x + first_char_width) // first_char_width ZeroDivisionError: integer division or modulo by zero

Additional Information

Please note that this issue has ONLY been tested in emulation mode! I do not have a Raspberry Pi yet to test on a physical setup. It appears the best solution would be to automatically remove emojis from MLB News Headline Names.

WardBrian commented 1 year ago

Do you know which team’s news feed lead to the headline appearing?

swemoney commented 1 year ago

I'm finding a play button ▶️ emoji starting to appear for "game story" articles. Just checked the astros feed

swemoney commented 1 year ago

I'm also seeing the play buttons on the cubs feed though. I'm testing the feed on my board now and haven't experienced a crash yet

WardBrian commented 1 year ago

The code that crashed is only in the emulator, not the actual board (I wrote it, I’m pretty sure) so I think it would need to be a different error

swemoney commented 1 year ago

Not seeing a crash on board. Just saw the Game Story article and it ended with a play icon and then a ? symbol (like it didn't understand the character)

ty-porter commented 1 year ago

Can you give the emulator version? It's possible this is an issue with RGBME and not this project.

Tyler Porter

On Thu, Apr 20, 2023, 7:41 PM swemoney @.***> wrote:

I'm finding a play button ▶️ emoji starting to appear for "game story" articles. Just checked the astros feed

— Reply to this email directly, view it on GitHub https://github.com/MLB-LED-Scoreboard/mlb-led-scoreboard/issues/463#issuecomment-1517063465, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALEAM5K5EX2Z7Z6W2MMQHSTXCHCR7ANCNFSM6AAAAAAXGEVKHA . You are receiving this because you are subscribed to this thread.Message ID: @.*** com>

randolph-gravely commented 1 year ago

@ty-porter how do I find the emulator version?

randolph-gravely commented 1 year ago

I am pretty new to programming, so I am not sure if this is the best way to fix the issue, but I did resolve it by removing emojis from headlines.

I did so by adding the following to the scrollingtext.py in the renderers folder:

from cleantext import clean

And then at line 28: clean_text = clean(text,normalize_whitespace=False, no_emoji=True, lower=False)

randolph-gravely commented 1 year ago

@WardBrian it was the Braves headlines that were causing the issue. It was the same thing that @swemoney described with the Astro's: it had the play emoji ("▶️ ") present in several article headlines

ty-porter commented 1 year ago

@ty-porter how do I find the emulator version?

python3 -m pip show RGBMatrixEmulator
ty-porter commented 1 year ago

I can reproduce this in emulator v0.8.3

Steps to trigger the bug:

  1. Character not in font
  2. Missing character is the first character in the string
  3. Text origin is < 0 (off matrix to the left)

For this specific trigger that would mean the string needs an emoji as the first character of a string that's large enough to scroll. The error will happen when the scrolling goes offscreen

I will fix this upstream in RGBME, however the fix there will be to gracefully handle 0 width characters. Missing characters will still show a (?) icon. If that's something we want to fix as well, we would need work in this project.

ty-porter commented 1 year ago

Resolved in #465.