Skip to content

Fix NullPointerException in LogicBlock.updateLinks() when linksVar is null#12241

Open
ZenthXSin wants to merge 1 commit into
Anuken:masterfrom
ZenthXSin:fix-logic-block-null-linksvar
Open

Fix NullPointerException in LogicBlock.updateLinks() when linksVar is null#12241
ZenthXSin wants to merge 1 commit into
Anuken:masterfrom
ZenthXSin:fix-logic-block-null-linksvar

Conversation

@ZenthXSin

Copy link
Copy Markdown

Bug Fix

Problem:
LogicBlock.LogicBuild.updateLinks() crashes with NullPointerException when linksVar is null.

java.lang.NullPointerException: Cannot assign field "numval" because "this.linksVar" is null
    at mindustry.world.blocks.logic.LogicBlock$LogicBuild.updateLinks(LogicBlock.java:610)
    at mindustry.world.blocks.logic.LogicBlock$LogicBuild.updateTile(LogicBlock.java:567)

Root Cause:
linksVar is annotated as @Nullable (line 266) and only initialized during code compilation in buildLASM() (line 392). However, updateLinks() (line 575) directly accesses linksVar.numval without null checking. This can happen when:

  • A logic block just spawned/placed and code hasn't compiled yet
  • Code compilation failed (exception caught, empty code loaded)
  • Link state changes before code is loaded

Fix:
Added null check at the beginning of updateLinks():

public void updateLinks(){
    if(linksVar == null) return;
    ...
}

This prevents the NPE and gracefully handles the case where links update before code compilation.

@cardillan

Copy link
Copy Markdown
Contributor

Just FYI, #12232 also fixes this (in the same way).

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