[Bug]: moveToken is one square off every N calls for tokens smaller than medium

Open
#5,968 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
java
Domain
game-dev

Research direction

Start with TokenLocationFunctions.java and inspect moveToken, especially the pixel-offset adjustment and the conversion to a ZonePoint. Reproduce the report by repeatedly calling moveToken(0, 0, 1, getSelected()) with a token smaller than medium; done means repeated calls leave the token at (0, 0).

Written by the indexing model from the issue text.

Description

bug
Describe the Bug

[moveToken(0, 0, 1, getSelected())] called repeatedly sometimes moves the token to (-1, -1).
This happens only for tokens with size smaller than "medium".
This happens only for "units" = 1, moveToken(0, 0, 0, ...) works as expected.
If the token is small, it lands every 8 calls on (-1, -1)
If the token is tiny or smaller it lands every 4 calls on (-1, -1)

Without understanding quite what happens here, I suspect this code might be the problem:
Its in TokenLocationFunctions.java:moveToken

if (useDistance) {
      // Remove pixel offset, so that getTokenX / getTokenY and coordinates match. Fixes #1757.
      Point offset = getInstance().getTokenPixelLocationOffset(token);
      x -= offset.x;
      y -= offset.y;
    }
    ZonePoint zp = getZonePoint(x, y, useDistance);
    MapTool.serverCommand().updateTokenProperty(token, Token.Update.setXY, zp.x, zp.y);

This happens with other coordinates, too, (0, 0) is just an example.

To Reproduce

Add a token to your map, select it and set its size to smaller than "medium".
Execute [moveToken(0, 0, 1, getSelected())] in the chat window repeatedly.

If you impersonate the token, [moveToken(0, 0)] will give the same buggy result.

Expected Behaviour

The Token is moved to (0, 0) and stays there for every subsequent call.

Screenshots

No response

MapTool Info

1.18.6, Jar-Install

Desktop

Linux (Gentoo)

Additional Context

==== MapTool Information ====
MapTool Version: 1.18.6
MapTool Home...: /home/stephan/.maptool-rptools
MapTool Install: /home/stephan/Anwendungen/MapTool-1.18.6/lib/app
Max mem avail..: 23 GB
Max mem used...: 272 MB
Custom Property: -DMAPTOOL_LOGDIR=/home/stephan/.maptool-rptools/logs
Custom Property: -DMAPTOOL_DATADIR=.maptool-rptools

==== Java Information ====
Java Home......: /home/stephan/Anwendungen/MapTool-1.18.6/lib/runtime
Java Vendor....: Eclipse Adoptium
Java Version...: 21.0.1
Java Parameters:
-Djpackage.app-version=1.0
-Xss8M
-Dsun.java2d.d3d=true
-Dsentry.environment=Production
-Dfile.encoding=UTF-8
-Dpolyglot.engine.WarnInterpreterOnly=false
-Djava.util.Arrays.useLegacyMergeSort=true
-XX:+ShowCodeDetailsInExceptionMessages
--add-opens=java.desktop/java.awt=ALL-UNNAMED
--add-opens=java.desktop/java.awt.geom=ALL-UNNAMED
--add-opens=java.desktop/sun.awt.geom=ALL-UNNAMED
--add-opens=java.base/java.util=ALL-UNNAMED
--add-opens=javafx.web/javafx.scene.web=ALL-UNNAMED
--add-opens=javafx.web/com.sun.webkit=ALL-UNNAMED
--add-opens=javafx.web/com.sun.webkit.dom=ALL-UNNAMED
--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.desktop/sun.awt=ALL-UNNAMED
--add-opens=java.desktop/sun.java2d=ALL-UNNAMED
--add-opens=java.desktop/javax.swing=ALL-UNNAMED
--add-opens=java.desktop/sun.awt.shell=ALL-UNNAMED
--add-opens=java.desktop/com.sun.java.swing.plaf.windows=ALL-UNNAMED
-Duser.country=DE
-Duser.language=de
-Djava.io.tmpdir=/home/stephan/tmp
-Djpackage.app-path=/home/stephan/Anwendungen/MapTool-1.18.6/bin/MapTool

==== OS Information ====
OS Name........: Linux
OS Version.....: 6.18.32-gentoo-r2
OS Architecture: amd64
PATH...........: /usr/local/sbin:/usr/local/bin:/usr/bin:/opt/bin:/usr/lib/llvm/21/bin:/usr/lib/llvm/20/bin:/opt/cuda/bin:/home/stephan/.local/share/JetBrains/Toolbox/scripts
Number of Procs: 28

==== User Information ====
User Name: stephan
User Home: /home/stephan
User Dir.: /home/stephan/Anwendungen/MapTool-1.18.6

==== Network Interfaces ====
Display Name..: eno1
Interface Name: eno1
Address...: 192.168.14.6

Display Name..: lo
Interface Name: lo
Address...: 127.0.0.1

Host Address...: 127.0.0.1
Default Gateway: 192.168.14.1

==== Locale Information ====
Country.: Germany
Language: German
Locale..: German (Germany)
Variant.:

==== Encoding Information ====
Default Locale: de_DE
Default Charset: UTF-8
file.encoding: UTF-8
sun.jnu.encoding: UTF-8
Default Encoding: UTF8

==== Display Information ====
Number of Displays: 3
Display 1: 5760x1080(-1)
Display 2: 1920x1080(-1)
Display 3: 1920x1080(-1)

==== Internet Gateway Devices ====
No IGDs Found!

Dominant language
Java
Stars
927
Forks
286
Avg merge
3d 17h
Merged PRs (30d)
94

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from RPTools/maptool

All issues in RPTools/maptool

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.