Maptool: “Select next/previous token” in Selection window broken

Created on 8 May 2020  Â·  9Comments  Â·  Source: RPTools/maptool

Describe the bug
When pressing “Select next token” or “Select previous token” in the Selection window, while having a token on the Object layer selected and another token being on the Token layer results in a NullPointerException.

Regardless of the current selected layer, if there are no tokens selected, pressing “Select next token” or “Select previous token” select tokens from the Token layer, not from the currently active layer.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new campaign.
  2. Add a token to the Token layer.
  3. Select Object (or Hidden) layer.
  4. Add token to the Object (or Hidden) layer.
  5. Open the Selection window.
  6. Select the token on the Object (or Hidden) layer.
  7. Press “Select next token” or “Select previous token”.

Expected behavior
In this specific case, I expect nothing to happen, as there is no next token on the selected layer. I expect that “Select next token” or “Select previous token” selects the next or previous of the currently active layer.

MapTool Info

  • Version: 1.6.1
  • Install: Upgrade

Desktop (please complete the following information):

  • OS: macOS
  • Version 10.15.4

Additional context
The error message:

java.lang.NullPointerException
    at net.rptools.maptool.client.ui.zone.ZoneRenderer.cycleSelectedToken(ZoneRenderer.java:4012)
    at net.rptools.maptool.client.ui.macrobuttons.panels.MenuButtonsPanel$9.mouseReleased(MenuButtonsPanel.java:135)
    at java.desktop/java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:298)
    at java.desktop/java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:297)
    at java.desktop/java.awt.Component.processMouseEvent(Component.java:6589)
    at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
    at java.desktop/java.awt.Component.processEvent(Component.java:6354)
    at java.desktop/java.awt.Container.processEvent(Container.java:2261)
    at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4966)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2319)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4798)
    at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4914)
    at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4543)
    at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4484)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2305)
    at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2772)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4798)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
    at java.desktop/java.awt.EventQueue.access$600(EventQueue.java:97)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:97)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
    at net.rptools.maptool.client.swing.MapToolEventQueue.dispatchEvent(MapToolEventQueue.java:110)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
bug tested

All 9 comments

checking, very likely related to my change

I don’t think so. This happens in 1.6.1 as well.

yeah, just reproduced in old version. I can have a look though.

Happens on any layer other than Token layer.

Easy to fix. The 'next token' functionality only goes to a token on the token layer though.

That sounds wrong if one is looking at the object layer as in this case. Would the expected behavior be that the next token on the same layer is selected?

Would the expected behavior be that the next token on the same layer is selected?

At least I’d expect that, yes.

Tested on all four layers. No more exceptions.

Minor issue. Doing a Revert on a layer with no tokens, or with no tokens selected, causes the first token on the Token layer to be shown _in the Selection window_. It is not, however, selected on the map.

  1. On new map, drop a token on Token layer.
  2. Switch to Background layer.
  3. Click on Revert in Selection window.
  4. Selection window will show token from Token layer as selected.

So there are two things here

a) The ZoneRenderer tries pretty hard to only have selected tokens from active zone - in undoSelectToken() it doesn't. I'm changing that so an undo kicks out tokens that are not in the active layer. This fixes the revert going back to that initial token on the non active layer in Selection window, while the zonerenderer doesn't show this selection for non-active layer.

b) The selection window continues to show selection when a layer is changed even though the zone renderer has already cleared the selection. I'm changing that so setActiveLayer() does an updateAfterSelection(). This means the Selection window's list of shown tokens is cleared as well. IF the user goes back to the layer they were looking before that, then they can still undo the token selection.

Tested. Using Revert button no longer displays a token from a different layer in the Selection window.

Next, Previous, Select All, Select None buttons working as expected.

Was this page helpful?
0 / 5 - 0 ratings