Changes between Initial Version and Version 1 of Ticket #25012


Ignore:
Timestamp:
2026-11-08T07:10:57+01:00 (2 weeks ago)
Author:
daredemodaisuki
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #25012 – Description

    initial v1  
    2020Normally, the two fields "mode" and "pWays" must always be consistent (i.e. mode == Mode.DRAGGING implies pWays != null). But if JOSM loses focus when dragging:
    2121
    22 1. When the window loses focus during a drag, the mouseReleased event is never delivered, so
    23    mouseReleased() is not called. The action therefore stays in the "dragging" state forever:
    24    mode == Mode.DRAGGING, mouseIsDown == true, mouseHasBeenDragged == true, and
    25    pWays still points to the preview object.
     221. When the window loses focus during a drag, the mouseReleased event is never delivered, so mouseReleased() is not called. The action therefore stays in the "dragging" state forever: mode == Mode.DRAGGING, mouseIsDown == true, mouseHasBeenDragged == true, and pWays still points to the preview object.
    2623
    27242. On the next mousePressed(MouseEvent), the existing pWays is discarded:
    … …  
    3027           pWays = null;
    3128       }
    32    but mode and mouseIsDown/mouseHasBeenDragged are not reset at this point. Normally this is
    33    masked because mouseReleased() resets them, but in this scenario mouseReleased() has already
    34    been lost.
     29   but mode and mouseIsDown/mouseHasBeenDragged are not reset at this point. Normally this is masked because mouseReleased() resets them, but in this scenario mouseReleased() has already been lost.
    3530
    36 3. The subsequent mouseDragged(MouseEvent) passes the checks at the top of the method
    37    (mouseIsDown is still true, and the INITIAL_MOVE_DELAY of 200 ms has already elapsed), but the
    38    block "if (mode == Mode.NORMAL) { ... initParallelWays(...) }" is skipped because mode is still
    39    DRAGGING. Execution falls through to:
     313. The subsequent mouseDragged(MouseEvent) passes the checks at the top of the method (mouseIsDown is still true, and the INITIAL_MOVE_DELAY of 200 ms has already elapsed), but the block "if (mode == Mode.NORMAL) { ... initParallelWays(...) }" is skipped because mode is still DRAGGING. Execution falls through to:
    4032
    4133       ParallelWays.ClosestPoint closest = pWays.closestPoint(enp);   // pWays == null
    … …  
    4840           at org.openstreetmap.josm.actions.mapmode.ParallelWayAction.mouseDragged(ParallelWayAction.java:407)
    4941
    50 So the combination "mode == DRAGGING while pWays == null" is what triggers the crash. The same
    51 stale mouseHasBeenDragged flag is also why a plain click after returning to the window takes the
    52 "end of drag" branch of mouseReleased() and clears the source ways.
     42So the combination "mode == DRAGGING while pWays == null" is what triggers the crash. The same stale mouseHasBeenDragged flag is also why a plain click after returning to the window takes the "end of drag" branch of mouseReleased() and clears the source ways.
    5343
    54 The screenshot tool is just one easy way to lose the mouseReleased event; alt-tabbing, a popup
    55 window stealing the button release, or a modal dialog appearing mid-drag should have the same
    56 effect.
     44The screenshot tool is just one easy way to lose the mouseReleased event; alt-tabbing, a popup window stealing the button release, or a modal dialog appearing mid-drag should have the same effect.
    5745
    5846It might be helpful to reset the whole drag state in mousePressed():