My be the same as bug [#4259]
Princess throwing a NPE exception:
Exception in thread "Princess-precognition (Draconis Combine)" java.lang.NullPointerException
at megamek.common.Game.getEntities(Game.java:1510)
at megamek.common.Game.getEntities(Game.java:1493)
at megamek.common.Compute.isEnemyIn(Compute.java:368)
at megamek.common.MoveStep.isMovementPossible(MoveStep.java:2910)
at megamek.common.pathfinder.MovePathFinder$MovePathLegalityFilter.shouldStay(MovePathFinder.java:181)
at megamek.common.pathfinder.MovePathFinder$MovePathLegalityFilter.shouldStay(MovePathFinder.java:149)
at megamek.common.pathfinder.AbstractPathFinder$Filter.doFilter(AbstractPathFinder.java:113)
at megamek.common.pathfinder.AbstractPathFinder.run(AbstractPathFinder.java:296)
at megamek.common.pathfinder.AbstractPathFinder.run(AbstractPathFinder.java:325)
at megamek.client.bot.princess.PathEnumerator.recalculateMovesFor(PathEnumerator.java:219)
at megamek.client.bot.princess.Precognition.run(Precognition.java:196)
Thanks,
Dav
This actually isn't just a princess issue. This is an issue with the entity position cache in Game. It looks like for some reason there' are stale entity Ids in the cache.
I'm actually going to go back on my previous statement. I now wonder if this might be related to concurrency issues. I could especially see this being the case in a game with simultaneous firing on (which is not compatible with Princess, partially because of concurrency issues).
I cannot find any way that Game.entityPosLookup would be out of sync with Game.entityIds. The only way I could see this happening if something like Game.reindexEntities() is being called concurrently with Game.getEntities(2). This could potentially happen if Precognition is running while the game phase changes or possibly when a turn ends (whenever the Server sends a new Entities vector to the Client).
I guess one option would be to make Game thread safe...
Your hypothesis is sound as Precognition spins off it's own threads so Princess can be "thinking" while other things are going on.
Making Game thread-safe is the best long-term fix. I know it's a big undertaking (because I've started on some of it) and there's a good chance of a performance hit, but not only can it fix this issue, it should help prevent future issues.
Yea, when I was looking into Princess threading issues with simltaneous phases, I had considered making Game thread safe, but it seemed like a lot of work, and I wasn't sure it was necessary.
I agree that it's probably something we should do, but I didn't want to expend the effort on it at the time. If you're already working on it, I can reassign the ticket to you (or you can reassign the ticket to you).
Yeah, I'll go ahead and take it. I'll go at a bit at a time, starting with the entity position cache.
I just submitted [r11333] to make the entity position cache thread safe. I'm not closing this ticket at this time as we haven't positively identified that as the cause of the issue (though it's a fair bet).
Related
Commit: [r11333]
As this NPE hasn't happened in my testing and hasn't been re-reported since [r11333], I'm marking this closed. If it happens again, please open a new ticket and attach the full log and save files.
Related
Commit: [r11333]