oripa / oripa

ORIPA is a drawing software dedicated to designing the crease patterns of origami. The unique feature of ORIPA is calculation of the folded shape from the pattern.
GNU General Public License v3.0
246 stars 42 forks source link

NullPointerException while enlarging selection #184

Closed lifesbest23 closed 2 years ago

lifesbest23 commented 2 years ago

While testing the new selection enlarger action I got the following NullPointerException, when I tried to drag/enlarge any set of selected lines while the mouse hovered over any of the selectable lines. To reproduce you just have to drag at any time when there is no pink mouseStartPoint visible.

 java.lang.NullPointerException
    at oripa.gui.presenter.creasepattern.enlarge.EnlargeLineAction.onDrag(EnlargeLineAction.java:158)
    at oripa.gui.view.main.PainterScreen.mouseDragged(PainterScreen.java:364)
    at java.desktop/java.awt.Component.processMouseMotionEvent(Component.java:6684)
    .......

The exception also appears when using centered scaling.

It can be fixed by checking if EnlargeLineAction.mouseStartPoint is defined before executing EnlargeLineAction:onDrag.

In addition to that I found the starting point selection should be possible even if paintContext.getCandidateLineToPick() is not null. The current implementation prevents certain corners from being the start point, if there are selectable lines around it at least 45° apart from each other, like here: image

lifesbest23 commented 2 years ago

I see you just fixed the second part with b3b0021c5aeba2a77ea46e0ad1cb83ddf0571ba4 in #183

Ooouch1 commented 2 years ago

Thank you for testing!

I haven't noticed the exception but it seems to be fixed in the latest commit.

lifesbest23 commented 2 years ago

The error still occurs with the latest commit, even though less often. The corner selection works better but if you drag somewhere inside the rectangle or outside of it, too far away from any of the four corners, it still throws a NullPointerException. Another case for the error is when any other mouse button is pressed and released while dragging/scaling.

Since EnlargeLineAction:onDrag uses the mouseStartPoint, there should be a check before it is used.

I will add a comment in your PR with the change.

Ooouch1 commented 2 years ago

Your comment helps me a lot to realize the cause of error.

Another case for the error is when any other mouse button is pressed and released while dragging/scaling.

I can't reproduce this error because the touch pad of my Surface doesn't allow me to press 2 mouse buttons at the same time and I don't have a mouse. I added button type check on press/release/drag. I hope it will work.

lifesbest23 commented 2 years ago

With the newest changes I am no longer able to produce the error in any way. Great Fixes you applied there.

lifesbest23 commented 2 years ago

Fixed in 70cdcf5e263784d4617e80961c9ad50377cbf57e