Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random token numbering can result in duplicate token names #943

Closed
RicoTheBold opened this issue Nov 26, 2019 · 7 comments
Closed

Random token numbering can result in duplicate token names #943

RicoTheBold opened this issue Nov 26, 2019 · 7 comments
Assignees
Labels

Comments

@RicoTheBold
Copy link

RicoTheBold commented Nov 26, 2019

Describe the bug
Copying/cutting a token and pasting can result in duplicate token names due to some kind of error in validation. This appears to only occur across multiple Maptool sessions.

To Reproduce
Steps to reproduce the behavior:

  1. Load/create a campaign (tested with new one).
  2. Enable these token preferences:
    -Duplicate Token Numbering: Random
    -Show Numbering on: Name
    -New Token Naming: Use "Creature"
  3. Create a token. Copy/paste it so you have a bunch (I made 50 total).
  4. Add a macro to to the campaign to allow a check for duplicate names (I added/used the Wolph42 BoT macro, which I could include if needed).
  5. Run the macro - you should find no duplicates. At one point, I created many hundreds (thousands?) during testing without running into any at this step. The birthday paradox demonstrates that it should have created a duplicate if there wasn't something to prevent it (e.g., validation).
  6. Save the campaign. Close MapTool. (Bug does not occur if you just reload the campaign)
  7. Launch MapTool. Load the campaign.
  8. Copy the tokens and paste them (as mentioned before, tested with 50, so now there are 100).
  9. Check for duplicates - you now likely have several. (The BoT macro has a function I didn't copy that's used to process the list of duplicates, so it gives an error instead of reporting anything, but a visual inspection of the Map Explorer can also verify them as shown in the screenshot).

Expected behavior
MapTool should not create duplicate token names just because it has been closed and reopened. Users are instructed not to ever use duplicate token names. http://lmwcs.com/rptools/wiki/Introduction_to_Mapping#Changing_a_Token.27s_Name.2C_GM_Name.2C_and_Label

Screenshots
duplicate tokens

MapTool Info

  • Version: 1.5.7
  • Install: Upgrade from 1.5.6, many previous versions

Desktop (please complete the following information):

  • OS: Windows
  • Version 10, version 1909 (OS Build 18363.476)

Additional context
Debug info:

==== MapTool Information ==== MapTool Version: 1.5.7 MapTool Home...: C:\Users\Rico\.maptool-rptools Max mem avail..: 4 GB Max mem used...: 254 MB Custom Property: -DMAPTOOL_DATADIR=.maptool-rptools

==== Java Information ====
Java Vendor.: Oracle Corporation
Java Home...: C:\Users\Rico\AppData\Local\MapTool\runtime
Java Version: 10.0.1

==== OS Information ====
OS Name........: Windows 10
OS Version.....: 10.0
OS Architecture: amd64
PATH...........: C:\Users\Rico\AppData\Local\MapTool\app;C:\Users\Rico\AppData\Local\MapTool
Number of Procs: 8

==== User Information ====
User Name: Rico
User Home: C:\Users\Rico
User Dir.: C:\Users\Rico\AppData\Local\MapTool\app

==== Network Interfaces ====
Display Name..: Software Loopback Interface 1
Interface Name: lo
Address...: 127.0.0.1
Address...: 0:0:0:0:0:0:0:1

Display Name..: LogMeIn Hamachi Virtual Ethernet Adapter
Interface Name: eth4
Address...: 2620:9b:0:0:0:0:1903:3c87
Address...: fe80:0:0:0:c527:65f5:a8ae:ced3%eth4

Display Name..: Qualcomm Atheros QCA61x4A Wireless Network Adapter
Interface Name: wlan3
Address...: 192.168.1.181
Address...: fe80:0:0:0:d586:e408:bfe6:492d%wlan3

Host Address...: 192.168.1.181
Default Gateway: 192.168.1.1

==== Locale Information ====
Country.: United States
Language: English
Locale..: English (United States)
Variant.:

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

==== Display Information ====
Number of Displays: 1
Display 1: 3840x1080(32)

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

@Phergus Phergus added the bug label Nov 26, 2019
@JamzTheMan
Copy link
Member

The random generator must be keeping a list of used numerals in memory.

Question: if you use sequence vs random, does the count start over as well (I think this one checks for token names? At least partially)

@Phergus
Copy link
Contributor

Phergus commented Nov 26, 2019

Confirmed. Note that setting to Creature isn't required. It happens with File Name or Creature.

MT does keep a list of used random numbers assigned in memory which isn't preserved across restarts of the program.

Choosing Increment for Duplicate Token Numbering does not have this issue. Subsequent copies continue on from last stopping point.

@RicoTheBold
Copy link
Author

Yeah, I should have tested with non-"Creature" settings, sorry. I stumbled into the issue when trying to figure out why I was having issues with Bag of Tricks "on token move" macros moving the wrong token, and it took some troubleshooting to even identify that I had duplicate token names, which led me to a whole new set of experimenting to see why that happened and finally narrow down the key variable was multiple MapTool sessions.

As an interesting coincidence, I happened to stumble on my first rptools.net forum post from September 2009, which just happened to be a bug report on random token naming way back in 1.3b57 with Azhrei being the first to respond. I was reading a bunch of these github issues to make sure this was a new issue and saw Azhrei is still active, so thanks for 10 years of MapTool improvements, and thanks to all of you other contributors for keeping this project thriving. I've been loving the 1.5x changes from the merging in of Jamz's fork.

@Azhrei
Copy link
Member

Azhrei commented Nov 26, 2019

Phergus wrote:

MT does keep a list of used random numbers assigned in memory which isn't preserved across restarts of the program.

Does it actually keep a list? IIRC, it generates a random number and then checks to see if a token with that name already exists by calling findToken() (or similar) and seeing if there's a return value. This isn't a great approach; assuming a two-digit random number field, after using up 98 of them, the random number generator will need to generate a lot of values before it finally hits the one that isn't allocated yet. I don't recall ever seeing this issue when testing with dozens of tokens, but maybe that isn't a large enough data set to trigger the issue reliably...

Rico wrote:

[...] thanks for 10 years of MapTool improvements, and thanks to all of you other contributors for keeping this project thriving. I've been loving the 1.5x changes from the merging in of Jamz's fork.

Yeah, it's been Jamz really keeping things alive on the coding side, but we now have a few more contributors — some code monkeys, some QA folks, some doc/wiki editors. All the thanks really go to the community for sticking around during the "dry spells"! ;)

@JamzTheMan
Copy link
Member

IIRC back in 1.4.1.x someone submitted an "improved" random generator, forgot what the improvement was, maybe the in memory list? I'm pretty sure there is a small class just for this.

@Phergus
Copy link
Contributor

Phergus commented Nov 26, 2019

@RicoTheBold - No worries on the Creature thing. I was just checking to make sure it wasn't connected to that option.

There have been a couple iterations of changes to the way the names are generated. Was it the 1.4.x change that went from 2 digit to 3 digit?

@Phergus
Copy link
Contributor

Phergus commented Jan 1, 2020

Closing.

@Phergus Phergus closed this as completed Jan 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants