[Bug report] + [Patch b89] NPE on token stacks

Notes on testing the latest builds of MapTool

Moderators: dorpond, trevor, Azhrei

Post Reply
User avatar
JamzTheMan
Great Wyrm
Posts: 1872
Joined: Mon May 10, 2010 12:59 pm
Location: Chicagoland
Contact:

[Bug report] + [Patch b89] NPE on token stacks

Post by JamzTheMan »

OK, so stumbled on what seems to be a bug in b89. I can only reliably replicate using one map (sorry, it's 40mb). Import into blank campaign under b89 and and click on Night Wisp (far upper right of token bunch) or any under him and press meta+shift+o (reset FOW). The NPE happens because I have a couple of tokens stacked and sometimes tokenStackMap is null (sometimes not). Sometimes you have to click or move and reclick, so it seems like a threading issue as it doesn't always happen.

Sorry, I have Lee's patch so my copy is a bit off from repository but this should easy to find. Also, I noticed a FIXME in another point doing a null check on the same. It doesn't seem tokenStackMap is ever properly intialized? Someone may want to give it a once over and there is probably a better way to fix it than what I provided.

possible patch

Code: Select all

Index: src/net/rptools/maptool/client/ui/zone/ZoneRenderer.java
===================================================================
--- src/net/rptools/maptool/client/ui/zone/ZoneRenderer.java	(revision 5962)
+++ src/net/rptools/maptool/client/ui/zone/ZoneRenderer.java	(working copy)
@@ -2406,6 +2453,10 @@
 					if (location.boundsCache.contains(currLocation.boundsCache)) {
 						if (tokenStackSet == null) {
 							tokenStackSet = new HashSet<Token>();
+							//Sometimes got NPE here
+							if(tokenStackMap == null)
+								tokenStackMap = new HashMap<Token, Set<Token>>();
 							tokenStackMap.put(token, tokenStackSet);
 							tokenStackSet.add(token);
-Jamz
____________________
Custom MapTool 1.4.x.x Fork: maptool.nerps.net
Custom TokenTool 2.0 Fork: tokentool.nerps.net
More information here: MapTool Nerps! Fork

User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: [Bug report] + [Patch b89] NPE on token stacks

Post by Azhrei »

So that patch applies to a check of code inside an IF block on line 2398 (in the original code):

2398: if (calculateStacks) {

However, line 2298 has the same IF statement and the block there is the one that allocates the tokenStackMap. There is no way for the predicate of the IF statement to change between the two locations, so the tokenStackMap must be set to null somewhere else. The obvious location is flush(), line 542.

The flush() function is called whenever something has changed in the Zone such that the map needs to be re-rendered. And not just visually redrawn, but actually recalculated. So zooming would cause it to be called, for example.

Unfortunately, that function is also called by putToken(). And putToken() is used by a lot of MTscript macros that want to force token updates to be pushed out to clients.

So now my question... Does this map you're testing with have an onSelection that might trigger a macro that calls putToken()? Or could the statsheet be referencing such a macro?

User avatar
JamzTheMan
Great Wyrm
Posts: 1872
Joined: Mon May 10, 2010 12:59 pm
Location: Chicagoland
Contact:

Re: [Bug report] + [Patch b89] NPE on token stacks

Post by JamzTheMan »

Hmm, I'll have to check. In my full campaign, I have the BoT and the Pathfinder framework so I'm sure there could be. But exporting this map and bringing it into a fresh b89 campaign, I believe it only has 2 or 3 lib tokens (mine) and pretty sure I don't have any fancy onXYZ events, just onCampaign. The statsheets are heavy but without the other libs it probably doesn't do much.

Wierd that it doesn't do it everytime either. I also have two places where I have 2 tokens on top of each other. Moving just the one fixes it so it's some sort of order or for some reason the other stack doesn't bother it. I was cutting/deleting/moving tokens all over to try and replicate it

Now it's only happening when I use cntrl+shift+o so I'm sure it's calling flush() right? It has to redraw all the lights, FoW, etc. Is any of those things done on it's own thread?
-Jamz
____________________
Custom MapTool 1.4.x.x Fork: maptool.nerps.net
Custom TokenTool 2.0 Fork: tokentool.nerps.net
More information here: MapTool Nerps! Fork

User avatar
JamzTheMan
Great Wyrm
Posts: 1872
Joined: Mon May 10, 2010 12:59 pm
Location: Chicagoland
Contact:

Re: [Bug report] + [Patch b89] NPE on token stacks

Post by JamzTheMan »

OK, so I was able to duplicate this in a fresh campaign now. I opened a new campaign, created 2 new tokens, changed them to PC, gave them sight, gave one darkvision the other normal sight.

Copied so I had about 50+, stacked a bunch. Selected far right token and meta-shift-o, bam! NPE. Now, sometimes I just got java.lang.NullPointerException, and sometimes I get a stack trace? SO, maybe happening in multiple locations?

This test campaign is only 151k so easier test :) Hopefully you can duplicate and it's not just me.
NPE Stacktrace

Code: Select all

Java.lang.NullPointerException
	at net.rptools.maptool.client.ui.zone.ZoneRenderer.renderTokens(ZoneRenderer.java:2391)
	at net.rptools.maptool.client.ui.zone.ZoneRenderer.renderZone(ZoneRenderer.java:1088)
	at net.rptools.maptool.client.ui.zone.ZoneRenderer.paintComponent(ZoneRenderer.java:685)
	at javax.swing.JComponent.paint(Unknown Source)
	at javax.swing.JComponent.paintChildren(Unknown Source)
	at javax.swing.JComponent.paint(Unknown Source)
	at javax.swing.JComponent.paintToOffscreen(Unknown Source)
	at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
	at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
	at javax.swing.RepaintManager.paint(Unknown Source)
	at javax.swing.JComponent._paintImmediately(Unknown Source)
	at javax.swing.JComponent.paintImmediately(Unknown Source)
	at javax.swing.RepaintManager$3.run(Unknown Source)
	at javax.swing.RepaintManager$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
	at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
	at javax.swing.RepaintManager.access$1000(Unknown Source)
	at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$200(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at net.rptools.maptool.client.swing.MapToolEventQueue.dispatchEvent(MapToolEventQueue.java:38)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
-Jamz
____________________
Custom MapTool 1.4.x.x Fork: maptool.nerps.net
Custom TokenTool 2.0 Fork: tokentool.nerps.net
More information here: MapTool Nerps! Fork

Post Reply

Return to “Testing”