maptool icon indicating copy to clipboard operation
maptool copied to clipboard

[Bug]: ClassCastException generated by Tokens with AStarCellPoints in LastPath

Open Phergus opened this issue 3 years ago • 10 comments

Describe the Bug

When loading older campaigns the tokens may have LastPath data using AStarCellPoints. This produces an exception causing the campaign load to fail.

java.lang.ClassCastException: class net.rptools.maptool.client.walker.astar.AStarCellPoint cannot be cast to class net.rptools.maptool.model.AbstractPoint (net.rptools.maptool.client.walker.astar.AStarCellPoint and net.rptools.maptool.model.AbstractPoint are in unnamed module of loader 'app')
	at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?]
	at java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1092) ~[?:?]
	at net.rptools.maptool.model.Path.toDto(Path.java:288) ~[main/:?]
	at net.rptools.maptool.model.Token.toDto(Token.java:2916) ~[main/:?]
	at net.rptools.maptool.model.Zone.lambda$toDto$29(Zone.java:2273) ~[main/:?]
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) ~[?:?]
...

To Reproduce

  1. Load attached campaign file in 1.12 beta or current dev branch.
  2. See exception

Expected Behaviour

Bad path data should be corrected on load

Remove .zip from filename. AStarCellPointError2.cmpgn.zip .

Screenshots

No response

MapTool Info

Current Dev and 1.12.0 beta 1

Desktop

Windows 10

Additional Context

Partially corrected in PR #3504.

Phergus avatar Aug 08 '22 20:08 Phergus

@Irarara you got this?

Phergus avatar Aug 08 '22 20:08 Phergus

👍

Since it was brought up on discord, is there any desire to actually restore the data? It still doesn't really seem necessary to me (since any token with this issue literally hasn't been touched in years), but I can make it happen if others think it's worthwhile.

Irarara avatar Aug 08 '22 20:08 Irarara

It guess it's the nice thing to do. In general I think it is handy to have last path preserved between sessions but as time goes on the information is probably less relevant. @kwvanderlinde @cwisniew @Azhrei thoughts?

Phergus avatar Aug 08 '22 20:08 Phergus

I'm always in favour of backwards compatibility unless it is onerous to do so. In this case it shouldn't be too hard if we do the touch-ups in Path.readResolve() where we can modify the lists instead of in Token.readResolve() where we can't.

And just so it's out there, our hunch is correct and we are seeing AStarCellPoint come after CellPoint, like in this path:

[CellPoint[9,10], net.rptools.maptool.client.walker.astar.AStarCellPoint@896, net.rptools.maptool.client.walker.astar.AStarCellPoint@896]

kwvanderlinde avatar Aug 08 '22 20:08 kwvanderlinde

Agreed. One thing MapTool has always been really good about is being able to read (even if not write) old campaigns, maps, and tokens.

Azhrei avatar Aug 08 '22 22:08 Azhrei

I feel bad saying this after I oh so confidently declared I'd make it happen, but I'm actually running into all sorts of issues trying to restore the data. Modifying the list seems like a no-go, and I'm having issues with even just generating a new path using the old points. Does anyone have any ideas on how to approach this properly? Or would like to just take a stab at it themselves?

Irarara avatar Aug 08 '22 22:08 Irarara

I'll take a look see if I can come up with something.

kwvanderlinde avatar Aug 08 '22 22:08 kwvanderlinde

Hmm, this is going to be tricky. Since the structure of AStarCellPoint has changed, it's not as simple as just reading x/y from an AStarCellPoint instance. It may be time for some xstream magic.

kwvanderlinde avatar Aug 08 '22 22:08 kwvanderlinde

@Irarara I'm happy to pick this up if you want. It is my fault for introducing this problem ...

kwvanderlinde avatar Aug 09 '22 07:08 kwvanderlinde

Sounds good, thanks. 🙂

Irarara avatar Aug 09 '22 12:08 Irarara

Tested. Example campaign no longer produces errors.

Phergus avatar Aug 15 '22 18:08 Phergus