Skip to content

Don't assume a level render state exists during extraction - #12

Closed
koolBEANS829 wants to merge 1 commit into
xpple:masterfrom
koolBEANS829:fix/portal-levelstate-npe
Closed

koolBEANS829 wants to merge 1 commit into
xpple:masterfrom
koolBEANS829:fix/portal-levelstate-npe

Conversation

@koolBEANS829

Copy link
Copy Markdown

Fixes #11.

extractWaypointBoxes assumes LevelExtractionContext#levelState is non-null.
Immersive Portals runs a second extraction pass for a portal's destination world from
SecondaryWorldRenderCore.renderDestWorld, and that pass has no level render state —
so the handler NPEs and the game crashes the moment a portal is on screen.

It only shows up once the current world has a waypoint, because the empty waypoint map
returns early before ever reaching levelState(). That makes it easy to miss: you can
play next to portals indefinitely, then crash the first time you add a waypoint.

This skips the extraction when there is no level state. Waypoints simply aren't
collected for the secondary pass and still render normally in the main view; the only
visible consequence is that they don't draw inside a portal view.

Testing

Built 1.4.0 with this change and reproduced the original crash first (waypoint set +
portal on screen → instant NPE), then confirmed it's gone with the patch, portals still
rendering see-through. Diffed the rebuilt jar against the released one — only
WaypointRenderingHelper*.class differ, so nothing else is in play.

I deliberately left renderWaypointBoxes unguarded (line 212 dereferences
LevelRenderContext#levelState the same way). I could not get that one to return null
across tens of thousands of portal render passes, so I didn't want to add a guard I
couldn't justify — happy to add it if you'd prefer the symmetry.

Context

Same root cause turned up in clientcommands, which bundles this mod as a JiJ
dependency: Earthcomputer/clientcommands#811 / Earthcomputer/clientcommands#812.

🤖 Generated with Claude Code

https://claude.ai/code/session_016LE8JscQsjVStsxdM6WcJV

Mods that render a secondary world reuse the level extraction pass for a
different level. Immersive Portals does this from
SecondaryWorldRenderCore.renderDestWorld when drawing a portal's
destination, and that pass has no level render state, so
LevelExtractionContext#levelState returns null and extractWaypointBoxes
NPEs as soon as a portal is on screen.

This only shows up once the world has a waypoint, since the empty
waypoint map returns early before reaching levelState().

Skip the extraction when there is no level state. Waypoints are simply
not collected for the secondary pass and still render normally in the
main view.

Fixes xpple#11

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016LE8JscQsjVStsxdM6WcJV
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.

NPE in extractWaypointBoxes when a waypoint is set and a portal is rendered

2 participants