gurkenlabs / litiengine

LITIENGINE 🕹 The pure 2D java game engine.
https://litiengine.com/
MIT License
731 stars 93 forks source link

Fix NullPointerException in TextRenderer#renderWithLinebreaks #822

Closed Mshnik closed 1 month ago

Mshnik commented 2 months ago

TextRenderer#renderWithLinebreaks throws a NullPointerException when invoked with a multiline string:

java.lang.NullPointerException: Cannot invoke "java.awt.font.TextLayout.getAscent()" because "nextLayout" is null
    at de.gurkenlabs.litiengine.graphics.TextRenderer.renderWithLinebreaks(TextRenderer.java:333)
        ...

I tracked this down to a typo on line 334: >= text.length() should be >= s.length(), as s is the string for the current line and text is the whole multiline string.

This pull request:

The unit test checks that no exception is thrown and that something is rendered, but I was unable to fully assert that the correct Glyphs are drawn due to Oracle locking down the sun.font module.

Mshnik commented 2 months ago

Amazing, your first Pull Request in the LITIENGINE repository! You have earned the rank of "contributor" - let us know your nickname in the Forum and on Discord so we can reward you with the new role :).

Oh nice! I would like the nickname Shnik, please 👍

WalterConway commented 2 months ago

Looks good to me.