Changeset 18987 in josm


Ignore:
Timestamp:
2024-02-16T08:53:31+01:00 (3 months ago)
Author:
GerdP
Message:

fix #23477: crash when undoing changes while in extrude mode

  • add sanity checks in performExtrusion() to detect when undo was pressed, this always cancels the current extrude
  • removes the try/catch clause which might hide a data corruption (reverts r12512)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java

    r18494 r18987  
    3939import org.openstreetmap.josm.data.coor.EastNorth;
    4040import org.openstreetmap.josm.data.coor.ILatLon;
    41 import org.openstreetmap.josm.data.osm.DataIntegrityProblemException;
    4241import org.openstreetmap.josm.data.osm.DataSet;
    4342import org.openstreetmap.josm.data.osm.Node;
     
    8281    private transient WaySegment selectedSegment;
    8382    private transient Node selectedNode;
     83    private transient Command lastCommandOnUndoStack;
    8484    private Color mainColor;
    8585    private transient Stroke mainStroke;
     
    332332        this.selectedNode = null;
    333333        this.selectedSegment = null;
     334        this.lastCommandOnUndoStack = null;
    334335        super.exitMode();
    335336    }
     
    402403        // If nothing gets caught, stay in select mode
    403404        if (selectedSegment == null && selectedNode == null) return;
     405        lastCommandOnUndoStack = UndoRedoHandler.getInstance().getLastCommand();
    404406
    405407        if (selectedNode != null) {
     
    546548                    addNewNode(e);
    547549                } else if (e.getPoint().distance(initialMousePos) > initialMoveThreshold && newN1en != null && selectedSegment != null) {
    548                     try {
    549                         // main extrusion commands
    550                         performExtrusion();
    551                     } catch (DataIntegrityProblemException ex) {
    552                         // Can occur if calling undo while extruding, see #12870
    553                         Logging.error(ex);
    554                     }
     550                    // main extrusion commands
     551                    performExtrusion();
    555552                }
    556553            } else if (mode == Mode.translate || mode == Mode.translate_node) {
     
    567564            mapView.removeTemporaryLayer(this);
    568565            selectedSegment = null;
     566            lastCommandOnUndoStack = null;
    569567            moveCommand = null;
    570568            mode = Mode.select;
     
    639637     */
    640638    private void performExtrusion() {
     639        // sanity checks, see #23447 and #12870: don't try to extrude when user pressed undo
     640        if (lastCommandOnUndoStack != UndoRedoHandler.getInstance().getLastCommand())
     641            return;
    641642        DataSet ds = getLayerManager().getEditDataSet();
     643        if (ds.getPrimitiveById(selectedSegment.getWay()) == null || !selectedSegment.isUsable())
     644            return;
     645
    642646        // create extrusion
    643647        Collection<Command> cmds = new LinkedList<>();
Note: See TracChangeset for help on using the changeset viewer.