Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undo/Redo may be crash #11

Closed
liyujiang-gzu opened this issue Aug 2, 2020 · 9 comments
Closed

Undo/Redo may be crash #11

liyujiang-gzu opened this issue Aug 2, 2020 · 9 comments
Labels
bug Something that needs to be fixed cannot reproduce Unable to reproduce this bug, assuming it's not an issue

Comments

@liyujiang-gzu
Copy link
Contributor

Please consider making a Pull Request if you are capable of doing so.

App Version:
2020.2.2 Develop branch, means all version has the bug.

Affected Device(s):
ViVo x27 with Android 10

Describe the bug

    java.lang.ArrayIndexOutOfBoundsException: length=10; index=-1
        at java.util.ArrayList.get(ArrayList.java:439)
        at com.lightteam.editorkit.feature.undoredo.UndoStack.pop(UndoStack.kt:37)
        at com.lightteam.editorkit.internal.UndoRedoEditText.redo(UndoRedoEditText.kt:119)
        at com.lightteam.modpeide.ui.editor.fragments.EditorFragment.onRedoButton(EditorFragment.kt:616)
        at com.lightteam.modpeide.ui.editor.utils.ToolbarManager$bind$5.onClick(ToolbarManager.kt:129)
        at android.view.View.performClick(View.java:7187)
        at android.view.View.performClickInternal(View.java:7164)
        at android.view.View.access$3500(View.java:813)
        at android.view.View$PerformClick.run(View.java:27649)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:230)
        at android.app.ActivityThread.main(ActivityThread.java:7742)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:508)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)
    fun pop(): TextChange {
        // TODO: size must >= 1
        val item = stack[size - 1]
        stack.removeAt(size - 1)
        currentSize -= item.newText.length + item.oldText.length
        return item
    }

To Reproduce
Steps to reproduce the behavior:

  1. Change content of Editor.
  2. Quick click undo or redo button.
  3. May be crash.

Expected behavior
No crash.

@liyujiang-gzu liyujiang-gzu added the bug Something that needs to be fixed label Aug 2, 2020
@massivemadness
Copy link
Owner

massivemadness commented Aug 3, 2020

It's important to call undoStack.canUndo() before calling this method. Does it really reproducible or you just removed all canUndo checks? 🤔 I can't reproduce it on my device, everything works fine

@massivemadness massivemadness added the cannot reproduce Unable to reproduce this bug, assuming it's not an issue label Aug 3, 2020
@liyujiang-gzu
Copy link
Contributor Author

It's important to call undoStack.canUndo() before calling this method. Does it really reproducible or you just removed all canUndo checks? 🤔 I can't reproduce it on my device, everything works fine

I fork develop branch, nothing to modified, but when you quickly double click Redo or Undo, it will crash. normal single click, it works fine.

@liyujiang-gzu
Copy link
Contributor Author

I can not found canRedo() or canUndo() in call strack:
EditorFragment.kt

    override fun onUndoButton() {
        // TODO: The below line not found `canUndo()`
        binding.editor.undo()
    }

    override fun onRedoButton() {
        binding.editor.redo()
    }

@liyujiang-gzu
Copy link
Contributor Author

liyujiang-gzu commented Aug 3, 2020

It's important to call undoStack.canUndo() before calling this method. Does it really reproducible or you just removed all canUndo checks? 🤔 I can't reproduce it on my device, everything works fine

Reproduce step:

  • Change text.
  • 【Duoble click】 Undo button 【quickly】.
  • Crash on my device.

@liyujiang-gzu
Copy link
Contributor Author

liyujiang-gzu commented Aug 3, 2020

When I change the text many times, I want quickly/fastly undo, but it crashed.😂😂😂
You can double click quickly/fastly to try again, may be reproduce.😹😹😹

@massivemadness
Copy link
Owner

@liyujiang-gzu Still cannot reproduce 😔
I really don't want to modify UndoStack.pop() because then it will have nullable return type.

Could you modify these methods and check it?

override fun onUndoButton() {
    if (binding.editor.canUndo()) {
        binding.editor.undo()
    }
}

override fun onRedoButton() {
    if (binding.editor.canRedo()) {
        binding.editor.redo()
    }
}

If everything will be fine, then I'll merge your PR into develop

@liyujiang-gzu
Copy link
Contributor Author

@liyujiang-gzu Still cannot reproduce
I really don't want to modify UndoStack.pop() because then it will have nullable return type.

Could you modify these methods and check it?

override fun onUndoButton() {
    if (binding.editor.canUndo()) {
        binding.editor.undo()
    }
}

override fun onRedoButton() {
    if (binding.editor.canRedo()) {
        binding.editor.redo()
    }
}

If everything will be fine, then I'll merge your PR into develop

A great idea. I think the reason was:

If you click too fast, `android:clickable="@{viewModel.canRedo}"` was too late to change to false and then click again, so undo / redo cause crash.

I modified the above methods, It‘s works to fine, Clicking too fast will no longer cause a crash

@massivemadness
Copy link
Owner

Alright, I'll change it later, but if you want you can make pull request with these changes

liyujiang-gzu added a commit to liyujiang-gzu/Brackeys-IDE that referenced this issue Aug 3, 2020
@liyujiang-gzu
Copy link
Contributor Author

I'll PR it later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that needs to be fixed cannot reproduce Unable to reproduce this bug, assuming it's not an issue
Projects
None yet
Development

No branches or pull requests

2 participants