Skip to content

ScreenPrompt.getWidgets() throws NPE when children() is called before the prompt is initialized #3965

Open

Description

@SolAstrius

Bug Description

When the donation prompt is pending, VideoSettingsScreen creates the ScreenPrompt early, but the prompt only builds its buttons in ScreenPrompt#init(), and VideoSettingsScreen#init() calls that after rebuild(). In that window children() already returns prompt.getWidgets(), which is List.of(this.actionButton, this.closeButton) with both still null, so it throws an NPE.

Vanilla never calls children() there so nothing breaks on its own, but children() is public API and any mod that looks at it during clearWidgets() crashes the game when opening Video Settings. I found it with CC: Graphics, which does exactly that (also reported at sashafiesta/CC-Graphics#3).

Reproduction Steps

  1. Sodium 0.8.13 + CC: Graphics 0.2.1, NeoForge 1.21.1
  2. In config/sodium-options.json set has_seen_donation_prompt to false, and set t in config/sodium-fingerprint.json to something small (or wait three days)
  3. Start the game and open Video Settings -> crash

Trace (trimmed):

Caused by: java.lang.NullPointerException
	at java.util.List.of(List.java:954)
	at net.caffeinemc.mods.sodium.client.gui.prompt.ScreenPrompt.getWidgets(ScreenPrompt.java:109)
	at net.caffeinemc.mods.sodium.client.gui.VideoSettingsScreen.children(VideoSettingsScreen.java:516)
	at net.minecraft.client.gui.screens.Screen.ccgraphics$closeGraphicsWidgets(Screen.java:756)
	at net.minecraft.client.gui.screens.Screen.clearWidgets(Screen.java)
	at net.caffeinemc.mods.sodium.client.gui.VideoSettingsScreen.rebuild(VideoSettingsScreen.java:172)
	at net.caffeinemc.mods.sodium.client.gui.VideoSettingsScreen.init(VideoSettingsScreen.java:143)

Easy fixes: call prompt.init() before rebuild(), or make getWidgets() skip buttons that haven't been created yet. I worked around it locally with the second. Same code is on dev (ScreenPrompt.java:101). Happy to PR if you want.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions