Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 of 2 tasks
randolph-gravely opened this issue Apr 20, 2023 · 12 comments · Fixed by #464
Closed
1 of 2 tasks

Comments

@randolph-gravely
Copy link

This issue is a

  • Bug Report
  • Feature Request

Hardware Configuration

  • Raspberry Pi Revision (4B+/3B+/Zero/etc.): N/A (RGB Emulator)
  • Operating System: Mac OS
  • Matrix size: 32 x 64
  • Display adapter (HAT/Bonnet/etc.): N/A
    • Additional information: N/A
  • Power source(s): N/A

Software Configuration v6.3.0

  • MLB LED Scoreboard Version:
  • Commands/arguments used to start the scoreboard:

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
Copy link
Member

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

@swemoney
Copy link
Collaborator

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

@swemoney
Copy link
Collaborator

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
Copy link
Member

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
Copy link
Collaborator

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
Copy link
Collaborator

ty-porter commented Apr 20, 2023 via email

@randolph-gravely
Copy link
Author

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

@randolph-gravely
Copy link
Author

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
Copy link
Author

@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
Copy link
Collaborator

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

python3 -m pip show RGBMatrixEmulator

@ty-porter
Copy link
Collaborator

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
Copy link
Collaborator

Resolved in #465.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants