Fix NPE in StatsAppState.setEnabled when called before initialization#2660
Open
Fix NPE in StatsAppState.setEnabled when called before initialization#2660
Conversation
When setEnabled() is called before initialize() (e.g. in simpleInitApp), fpsText/darkenFps/statsView/darkenStats are null, causing an NPE. Fix: add a null guard at the start of setEnabled() that returns early if the UI components haven't been created yet. The enabled flag is still saved via super.setEnabled(). Then, at the end of initialize(), call setEnabled(isEnabled()) to apply any pre-initialization enabled state to the freshly created components. Agent-Logs-Url: https://github.com/jMonkeyEngine/jmonkeyengine/sessions/4fd1f71f-451e-4425-8e83-ae69d6b1ce0a Co-authored-by: riccardobl <4943530+riccardobl@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix NPE in StatsAppState.setEnabled during app init
Fix NPE in StatsAppState.setEnabled when called before initialization
Mar 28, 2026
yaRnMcDonuts
approved these changes
Mar 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
StatsAppState.setEnabled()throws aNullPointerExceptionwhen called beforeinitialize()(e.g. fromsimpleInitApp), becausefpsText,darkenFps,statsView, anddarkenStatsare not yet created.Changes
setEnabled(): Added an early-return null guard onfpsText.super.setEnabled()is still called to persist the flag; the UI update is deferred until components exist.initialize(): CallssetEnabled(isEnabled())after loading all UI components, so any enabled state set pre-initialization is applied correctly.🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.