libgdx / libgdx/libgdx

Rare NPE in GlyphLayout

Open
#7,582 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
25.4k
Forks
6.5k
Avg merge
1d 16h
Merged PRs (30d)
5

Description

I have an Android app in the Play Store.
Rarely I see exceptions like this in the Google Play Console:

Exception java.lang.NullPointerException:
  at com.badlogic.gdx.graphics.g2d.GlyphLayout.setText (GlyphLayout.java:176)
  at com.badlogic.gdx.graphics.g2d.GlyphLayout.setText (GlyphLayout.java:95)
  at com.badlogic.gdx.scenes.scene2d.ui.Label.computePrefSize (Label.java:162)
  at com.badlogic.gdx.scenes.scene2d.ui.Label.scaleAndComputePrefSize (Label.java:147)
  at com.badlogic.gdx.scenes.scene2d.ui.Label.getPrefWidth (Label.java:244)
  at com.badlogic.gdx.scenes.scene2d.ui.Label.<init> (Label.java:75)

or:

(RuntimeException root cause)
Caused by java.lang.NullPointerException:
  at com.badlogic.gdx.graphics.g2d.GlyphLayout.calculateWidths (GlyphLayout.java:280)
  at com.badlogic.gdx.graphics.g2d.GlyphLayout.setText (GlyphLayout.java:266)
  at com.badlogic.gdx.graphics.g2d.GlyphLayout.setText (GlyphLayout.java:95)
  at com.badlogic.gdx.scenes.scene2d.ui.Label.computePrefSize (Label.java:162)
  at com.badlogic.gdx.scenes.scene2d.ui.Label.scaleAndComputePrefSize (Label.java:147)
  at com.badlogic.gdx.scenes.scene2d.ui.Label.getPrefWidth (Label.java:244)
  at com.badlogic.gdx.scenes.scene2d.ui.Label.<init> (Label.java:75)

or, maybe related:

Exception java.lang.IndexOutOfBoundsException:
  at com.badlogic.gdx.utils.Array.get (Array.java:155)
  at com.badlogic.gdx.graphics.g2d.GlyphLayout.setText (GlyphLayout.java:215)
  at com.badlogic.gdx.graphics.g2d.GlyphLayout.setText (GlyphLayout.java:101)
  at com.badlogic.gdx.scenes.scene2d.ui.Label.computePrefSize (Label.java:160)
  at com.badlogic.gdx.scenes.scene2d.ui.Label.scaleAndComputePrefSize (Label.java:147)
  at com.badlogic.gdx.scenes.scene2d.ui.Label.getPrefHeight (Label.java:253)
  at com.badlogic.gdx.scenes.scene2d.ui.Label.layout (Label.java:175)
  at com.badlogic.gdx.scenes.scene2d.ui.Widget.validate (Widget.java:88)
  at com.badlogic.gdx.scenes.scene2d.ui.Stack.layout (Stack.java:107)
  at com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup.validate (WidgetGroup.java:104)
  at com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup.layout (VerticalGroup.java:201)
  at com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup.validate (WidgetGroup.java:104)
  at com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.layout (ScrollPane.java:498)

It happens in different labels, but only in labels, and I'm not able to reproduce it.

libgdx version: 1.12.1

Any idea?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting GlyphLayout.setText and calculateWidths at the reported line numbers, then trace the Label constructor and its computePrefSize calls. The reports provide no reproduction or named test, so done would require identifying a reproducible cause and establishing a regression check or clearly scoped fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
game-dev, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.