question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BinaryHeap NullPointerException

See original GitHub issue

Issue details

In prev release 7 march (gdx-1.9.11-SNAPSHOT) my game worked fine

Reproduction steps/code

BinaryHeap<Node> bh = new BinaryHeap<Node>();
bh.add(new Node(5f));
Node node = new Node(10f);
bh.add(node);
bh.remove(node);
bh.remove(node);

Version of LibGDX and/or relevant dependencies

gdx-1.9.11-SNAPSHOT gdx-ai-1.8.2

Stacktrace

java.lang.NullPointerException: 
  at com.badlogic.gdx.utils.BinaryHeap.down (BinaryHeap.java:156)
  at com.badlogic.gdx.utils.BinaryHeap.remove (BinaryHeap.java:102)
  at com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder.visitChildren (IndexedAStarPathFinder.java:219)
  at com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder.search (IndexedAStarPathFinder.java:117)
  at com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder.searchNodePath (IndexedAStarPathFinder.java:94)
  at com.tpwar.game.maps.pathfinding.TiledPathFinder.find (TiledPathFinder.java:29)
  at com.tpwar.game.screens.MapScreen$InputAdapterExtension.touchUp (MapScreen.java:741)
  at com.badlogic.gdx.InputMultiplexer.touchUp (InputMultiplexer.java:124)
  at com.badlogic.gdx.backends.android.AndroidInput.processEvents (AndroidInput.java:406)
  at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame (AndroidGraphics.java:476)
  at android.opengl.GLSurfaceView$GLThread.guardedRun (GLSurfaceView.java:1581)
  at android.opengl.GLSurfaceView$GLThread.run (GLSurfaceView.java:1280)

image

Please select the affected platforms

  • Android
  • iOS (robovm)
  • iOS (MOE)
  • HTML/GWT
  • Windows
  • Linux
  • MacOS

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
tommyettingercommented, Apr 3, 2020

Yes! Not only can I confirm the bug, I can confirm a fix for the bug, and it only needs moving one line in BinaryHeap! The solution is to change, in BinaryHeap.remove(T):

			nodes[node.index] = moved;
			nodes[size] = null;

to

			nodes[size] = null;
			nodes[node.index] = moved;

I believe the issue happened when size and node.index were equal, so nodes[node.index] should have been moved but instead was null.

0reactions
NathanSweetcommented, Apr 3, 2020

Ah, that was tricky! Great find @tommyettinger!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Binary Heap – Data Structure - The Null Pointer Exception
A binary Heap is an array object. We can view that array object as a near complete binary tree. A binary tree is...
Read more >
NullPointerException when inserting into binary heap?
I'm trying to insert values into an initially empty binary heap. This is the relevant code: public class minHeap { int[] array; int...
Read more >
Null Pointer exception when extracting dump from core file ...
No translations currently exist. Issue. Cannot extract heap dump from core file with Java 11, using the following command: $JAVA_HOME/bin/jhsdb ...
Read more >
[Solved]-NullPointerException when inserting into binary heap?-Java
On your first insert, hole = 0 but obviously x is equal to array[hole/2] since hole/2 evaluates to 0, so this loop exits...
Read more >
BPEL - Failed to handle dispatch message ... exception ...
Hi, When I try to send a message to a BPEL process, it gives me a NullPointerException. ... BinaryHeap$MinComparator.compare(BinaryHeap.java:308)
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found