NullPointerException when using removeFromInitiative()

Developer discussion regarding MapTool 1.4

Moderators: dorpond, trevor, Azhrei

Forum rules
Posting now open to all registered forum users.
Post Reply
ZenCorrosion
Kobold
Posts: 15
Joined: Thu Mar 05, 2015 4:31 pm

NullPointerException when using removeFromInitiative()

Post by ZenCorrosion »

Hi all!

I'm working on a Feng Shui 2 framework that takes a different view of initiative. Each time your character acts, your initiative decreases. My attack macro decreases the attacker's initiative, then if they KO the target it removes the target from the initiative list. Finally, at the end it sorts the initiative list. If the KO macro removes the token from the initiative list (removeFromInitiative()) and the macro is on a library token, then I get an exception (stack trace below) when the attacker's initiative is lower than the target's initiative.

I tried creating a simple test case campaign file to show this more clearly, but didn't get the exception. I can provide my campaign file if that will help, the problem shows up regularly there. This problem occurs on MapTools 1.4.0.5.

Also, while searching the forum I found this thread which seems to be very similar. http://forums.rptools.net/viewtopic.php ... ve#p136903

While I'm here I just want to say "Thank you!" for all of the effort on MapTool over the years. I really love the flexibility it provides and hope it continues to develop and get even stronger.

-------------------------
java.lang.NullPointerException
at net.rptools.maptool.client.ClientMethodHandler$1.run(ClientMethodHandler.java:506)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at net.rptools.maptool.client.swing.MapToolEventQueue.dispatchEvent(MapToolEventQueue.java:36)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: NullPointerException when using removeFromInitiative()

Post by aliasmask »

null pointer is essentially not finding what you're looking for. So, for example if you try to remove a token from init but there is no impersonated token then it could give an error. Can't really get more detailed without seeing some code.

ZenCorrosion
Kobold
Posts: 15
Joined: Thu Mar 05, 2015 4:31 pm

Re: NullPointerException when using removeFromInitiative()

Post by ZenCorrosion »

OK, so to be a little more specific, in the campaign macro I call the KO macro on the library token with the target token name as the parameter:

[h: target = some_token_name]

...

[macro( "KO@Lib:ZC-FengShui2" ): target ]

----
Inside the KO macro I have:

[h: targetToken = macro.args]

[token( targetToken ), CODE: {
[h: setState( "Sitting Duck", 0 )]
[h: setState( "Incapacitated1", 0 )]
[h: setState( "Incapacitated2", 0 )]
[h: setState( "KO", 1 )]
[h: removeFromInitiative()]
}]
----

If I delete the call to removeFromInitiative(), I don't get the exception, and the states get cleared correctly. The exception still happens if I am impersonating the attacker token. One interesting thing is that I don't get the exception if I move the call to removeFromInitiative() from the library macro into the campaign macro:

[macro( "KO@Lib:ZC-FengShui2" ): target ]
[h, token( target: removeFromInitiative()]

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: NullPointerException when using removeFromInitiative()

Post by aliasmask »

try replacing token(targetToken) and code braces with switchToken(targetToken) and see if it makes a difference.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: NullPointerException when using removeFromInitiative()

Post by wolph42 »

i always forget but is the passed on argument not [some_token_name] instead of some_token_name which is what you assume it to be in your code. It would explain the error

ZenCorrosion
Kobold
Posts: 15
Joined: Thu Mar 05, 2015 4:31 pm

Re: NullPointerException when using removeFromInitiative()

Post by ZenCorrosion »

OK, I tried replacing the token roll option with switchToken(), but I can still get the same error.

[h:switchToken( targetToken )]
[h: setState( "Sitting Duck", 0 )]
[h: setState( "Incapacitated1", 0 )]
[h: setState( "Incapacitated2", 0 )]
[h: setState( "KO", 1 )]
[h: removeFromInitiative()]

ZenCorrosion
Kobold
Posts: 15
Joined: Thu Mar 05, 2015 4:31 pm

Re: NullPointerException when using removeFromInitiative()

Post by ZenCorrosion »

@wolph42, I'm guessing you're asking if some_token_name is an array?

I believe it is a string that has the name of a token. It's value is selected by a user through a list in an input dialog:
"target| " + json.toList( targets ) + "| My target is: | LIST | VALUE=STRING",

targets comes from getTokenNames( "json" )

Checking for the JSON type gives me:
macro args type = [r: json.type( macro.args) ]<br>
...
macro args type = UNKNOWN

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: NullPointerException when using removeFromInitiative()

Post by aliasmask »

I have a feeling it may be an MT timing thing when drawing the token and removing it from the panel. It may not like something that's going on. Put an input pause just before the remove token. Does it error? May as well make sure targetToken is valid as well.

ZenCorrosion
Kobold
Posts: 15
Joined: Thu Mar 05, 2015 4:31 pm

Re: NullPointerException when using removeFromInitiative()

Post by ZenCorrosion »

It does feel like a timing issue. If I put the removeFromInitiative() call into the calling macro instead of the KO macro, the problem is much reduced, although I do still see the issue occasionally.

I put an input dialog before the removeFromInitiative() call inside the macro as suggested and that too seems to fix the problem.

I guess for me, I'll stick with putting the call outside of the KO macro since I don't want another dialog popup.

Thanks for the help!

Post Reply

Return to “MapTool 1.4”