pastthepixels / FreePaint

A vector graphics drawing app for Android.
GNU General Public License v3.0
76 stars 7 forks source link

[Bug] FreePaint Bug Report (v1.2.0) #35

Open kaduvert opened 2 days ago

kaduvert commented 2 days ago

Checklist
In order for your bug report to be considered, please follow the checklist below. Ensure you have not deleted any points but instead checked them by replacing [ ] with [x] or clicking on the boxes.

Describe the bug

FATAL EXCEPTION: main
Process: io.github.pastthepixels.freepaint, PID: 25286
java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
    at jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
    at jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
    at jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
    at java.util.Objects.checkIndex(Objects.java:359)
    at java.util.ArrayList.get(ArrayList.java:434)
    at io.github.pastthepixels.freepaint.Graphics.DrawPath.simplify(DrawPath.java:193)
    at io.github.pastthepixels.freepaint.Graphics.DrawPath.finalise(DrawPath.java:137)
    at io.github.pastthepixels.freepaint.Tools.PaintTool.onTouchEvent(PaintTool.java:74)
    at io.github.pastthepixels.freepaint.Graphics.DrawCanvas.onTouchEvent(DrawCanvas.java:159)
    at android.view.View.performOnTouchCallback(View.java:16266)
    at android.view.View.dispatchTouchEvent(View.java:16223)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3125)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2806)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3125)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2806)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3125)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2806)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3125)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2806)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3125)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2806)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3125)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2806)
    at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:496)
    at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1952)
    at android.app.Activity.dispatchTouchEvent(Activity.java:4510)
    at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:70)
    at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:454)
    at android.view.View.dispatchPointerEvent(View.java:16548)
    at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:7559)
    at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:7326)
    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:6723)
    at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:6780)
    at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:6746)
    at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:6912)
    at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:6754)
    at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:6969)
    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:6727)
    at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:6780)
    at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:6746)
    at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:6754)
    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:6727)
    at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:9827)
    at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:9778)
    at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:9747)
    at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:9969)
    at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:295)
    at android.os.MessageQueue.nativePollOnce(Native Method)
    at android.os.MessageQueue.next(MessageQueue.java:349)
    at android.os.Looper.loopOnce(Looper.java:189)
    at android.os.Looper.loop(Looper.java:317)
    at android.app.ActivityThread.main(ActivityThread.java:8592)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)

To Reproduce
Steps to reproduce the behavior: => draw in the app idk

Expected behavior
works

kaduvert commented 2 days ago

https://github.com/pastthepixels/FreePaint/issues/26#issuecomment-2299638007 seems to be whats happening:

I think the most likely thing causing this is with my code regarding touch input. Basically it registers a point in a path when your finger goes down on the screen (including every time it's moved) and, when your finger is lifted, iterates through the list of points assuming there's at least one point. Maybe this is an edge case caused by your phone or OS telling FreePaint that your finger lifted from the screen before it told FreePaint that your finger even touched the screen, causing it to crash because it thinks there's at least one point.

pastthepixels commented 2 days ago

Thanks for the detailed bug report! Yeah, this is exactly what's happened - it should be merged in #33 for the upcoming v1.3.0. I also very recently completely rewrote the DrawPath class removing the need for a bunch of other null checks, so hopefully this fixes a bunch of other issues you might encounter relating to empty paths. A fix is definitely on its way though which I'll try to release soon™ after I'm done working on a few other issues and fixing the UX on some tools.