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

Fix NullPointerException in TextRenderer#renderWithLinebreaks #822

Merged
merged 6 commits into from
Jul 16, 2024

Conversation

Mshnik
Copy link
Contributor

@Mshnik Mshnik commented Jul 8, 2024

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:

  • Fixes the bug.
  • Adds a unit test for TextRenderer#renderWithLinebreaks.

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.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :).

@Mshnik
Copy link
Contributor Author

Mshnik commented Jul 8, 2024

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

Looks good to me.

Copy link
Member

@nightm4re94 nightm4re94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your improvements! I have only minor remarks (see comments).

@Mshnik Mshnik requested a review from nightm4re94 July 16, 2024 03:36
@nightm4re94 nightm4re94 merged commit cb5746d into gurkenlabs:main Jul 16, 2024
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 this pull request may close these issues.

3 participants