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

Crash on deleting a branch in combination with filtering #4179

Open
Krismix1 opened this issue Jan 17, 2025 · 4 comments · May be fixed by #4195
Open

Crash on deleting a branch in combination with filtering #4179

Krismix1 opened this issue Jan 17, 2025 · 4 comments · May be fixed by #4195
Labels
bug Something isn't working

Comments

@Krismix1
Copy link
Contributor

Describe the bug
Lazygit crashed with "invalid memory address or nil pointer dereference error" after deleting a branch and applying filtering.
It seems this was previously fixed in #3058, but it appeared again (I tested on commit 36918560, and it worked fine there).

To Reproduce
Steps to reproduce the behavior:

  1. Create a branch named "dummy"
  2. Focus branch list view
  3. Press /
  4. Type: dummy
  5. Press Enter, d, Enter

Expected behavior
I expected lazygit to continue and either redo the filter operation, or show all branches.

Screenshots
If applicable, add screenshots to help explain your problem.

Version info:
lazygit: commit=v0.45.0, build date=2025-01-11T10:02:55Z, build source=binaryRelease, version=0.45.0, os=linux, arch=amd64, git version=2.48.1
git version 2.48.1

Additional context

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x583685225cd2]

goroutine 325 [running]:
github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers.(*RefreshHelper).refreshBranches.func3(0x5836851883c5?)
        github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers/refresh_helper.go:495 +0x12
github.com/samber/lo.FindIndexOf[...]({0xc001a920c0?, 0x1, 0xc001a90000}, 0xc001613e50?)
        github.com/samber/[email protected]/find.go:54 +0x57
github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers.(*RefreshHelper).refreshBranches(0xc00074a680, 0x0, 0x0, 0x1)
        github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers/refresh_helper.go:494 +0x707
github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers.(*RefreshHelper).refreshReflogAndBranches(0xc00074a680, 0x0, 0x0)
        github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers/refresh_helper.go:273 +0x74
github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers.(*RefreshHelper).Refresh.func2.2()
        github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers/refresh_helper.go:130 +0x1f
github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers.(*RefreshHelper).Refresh.func2.1.1({0x0?, 0x0?})
        github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers/refresh_helper.go:107 +0x13
github.com/jesseduffield/gocui.(*Gui).onWorkerAux(0xc0003661c0, 0x0?, {0x5836856e1638?, 0xc00007b260?})
        github.com/jesseduffield/[email protected]/gui.go:701 +0x65
github.com/jesseduffield/gocui.(*Gui).OnWorker.func1()
        github.com/jesseduffield/[email protected]/gui.go:688 +0x2b
created by github.com/jesseduffield/gocui.(*Gui).OnWorker in goroutine 225
        github.com/jesseduffield/[email protected]/gui.go:687 +0x92

Note: please try updating to the latest version or manually building the latest master to see if the issue still occurs.
I tried compiling from master. The issue persists

@Krismix1 Krismix1 added the bug Something isn't working label Jan 17, 2025
@stefanhaller
Copy link
Collaborator

I tested this with your reproduction steps, and it didn't crash for me. The filtered list of branches was empty for me after deleting the branch.

Does this happen for you every time, or only sometimes? Maybe it's somehow timing sensitive.

@Krismix1
Copy link
Contributor Author

Krismix1 commented Jan 20, 2025

Hey @stefanhaller ,
This happens every time. I also tried pressing the buttons slower, with several seconds in between (if that is what you mean), but it crashed anyway.

I ended up firing a debugger and I think I can see why it happens/how to reproduce: in the unfiltered view, take note of the branch that is last in the list. Now filter the list, select the branch and delete it.

Let me know if it reproduces with this approach. It's easier to reproduce if you only have 2 branches in the repo.

You don't necessarily need to delete the last branch from the unfiltered view. You just have to ensure the last branch is present in the filtered view.
Cause if the last branch was in the filtered view, this will cause the call to ValuesAtIndices to contain in index outside of the slice - slice will contain the new list of branches but indices will be based on the old list of branches, which causes result to be something like [..., nil].

@stefanhaller
Copy link
Collaborator

Yes, I can easily reproduce it by filtering down to just the last branch in the list and trying to delete that.

I'll see if I can come up with a fix tomorrow.

@stefanhaller
Copy link
Collaborator

Here's a possible fix: #4195. It's a draft PR for now because I didn't get around to adding a test yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants