vasl-developers / vasl

Virtual Advanced Squad Leader
http://vasl.info/
GNU Lesser General Public License v2.1
66 stars 27 forks source link

Draggable Overlays bug #1787

Open derimmer opened 1 month ago

derimmer commented 1 month ago

In linux, using VASL6.6.9-betaX, when dragging overlays from the draggable overlays window, the dragged item is not visible once it leaves the window and enters the map. It appears when dropped.

This appears to be one of the last remaining ASLPieceMover issues. Discussed on Discord July 2024.

uckelman commented 1 month ago

The bug is in ASLPieceMover.AbstractDragHandler.buildBoundingBox():

final ASLMap map = (ASLMap) firstPiece.getMap();
double pZoom = map.PieceScalerBoardZoom(firstPiece);

If you check the errorLog, you'll see that you get an NPE from the second line:

2024-07-27 13:24:01,805 [30864-AWT-EventQueue-0] WARN  VASSAL.tools.logging.LoggedOutputStream - java.lang.NullPointerException: Cannot invoke "VASL.build.module.ASLMap.PieceScalerBoardZoom(VASSAL.counters.GamePiece)" because "map" is null
2024-07-27 13:24:01,805 [30864-AWT-EventQueue-0] WARN  VASSAL.tools.logging.LoggedOutputStream -    at VASL.build.module.map.ASLPieceMover$AbstractDragHandler.buildBoundingBox(ASLPieceMover.java:1034)
2024-07-27 13:24:01,806 [30864-AWT-EventQueue-0] WARN  VASSAL.tools.logging.LoggedOutputStream -    at VASL.build.module.map.ASLPieceMover$AbstractDragHandler.makeDragImageCursorCommon(ASLPieceMover.java:970)
2024-07-27 13:24:01,806 [30864-AWT-EventQueue-0] WARN  VASSAL.tools.logging.LoggedOutputStream -    at VASL.build.module.map.ASLPieceMover$DragHandlerNoImage.makeDragCursor(ASLPieceMover.java:1636)
2024-07-27 13:24:01,806 [30864-AWT-EventQueue-0] WARN  VASSAL.tools.logging.LoggedOutputStream -    at VASL.build.module.map.ASLPieceMover$DragHandlerNoImage.dragEnter(ASLPieceMover.java:1754)
2024-07-27 13:24:01,806 [30864-AWT-EventQueue-0] WARN  VASSAL.tools.logging.LoggedOutputStream -    at java.desktop/java.awt.dnd.DropTarget.dragEnter(DropTarget.java:358)

The reason this happens is the one I noted here. Pieces being dragged off a piece palette do not have a map set.

You should not be using the scale factor of anything inside buildBoundingBox(). It is intended to produce an unscaled bounding box. Scale the bounding box and relative location lists where they are used.

derimmer commented 1 month ago

I can trap the NPE error that you flag. I have added some error handling that I hope will fix the disappearing bug (can't replicate on my windows device) temporarily while we try and address the broader issue of refactoring buildBoundingBox and related code. @jrvjrv here is a link to a beta with this error handling. Could you test it and let us know if this fixes the disappearing drag image? https://www.dropbox.com/scl/fi/i09idhn4skn7t8px8ohb0/vasl-6.6.9-linux-bug-v2-beta7.vmod?rlkey=dzygkmt69z6nv6sbjxfebj5fo&dl=0

I am going to hold off on removing scaling from buildBoundingBox() until I get a chance to talk to John Young who added these changes as part of the BoardZoomer.