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

Invalid buffer id-errors #266

Open
LiveNL opened this issue Feb 25, 2024 · 3 comments
Open

Invalid buffer id-errors #266

LiveNL opened this issue Feb 25, 2024 · 3 comments

Comments

@LiveNL
Copy link

LiveNL commented Feb 25, 2024

Hi,

From time to time I experience 'Invalid buffer id' errors. So far, it is unclear why and how these are deterministically being triggered, and therefore I'm also unsure how to provide a path to replicate the error.

Below you can find a screenshot of error.

Screenshot 2024-02-24 at 20 29 27

As a suggestion, I'm experimenting with the following change in my code locally (creating branches is forbidden):

--- a/lua/alpha.lua
+++ b/lua/alpha.lua
@@ -618,6 +618,12 @@ function alpha.draw(conf, state)
     -- when the screen is cleared and then redrawn
     -- so we save the index before that happens
     local ix = cursor_ix
+
+    -- Check if the buffer is valid before proceeding
+    if not vim.api.nvim_buf_is_valid(state.buffer) then
+        return
+    end
+
     vim.api.nvim_buf_set_option(state.buffer, "modifiable", true)
     vim.api.nvim_buf_clear_namespace(state.buffer, -1, 0, -1)
     vim.api.nvim_buf_set_lines(state.buffer, 0, -1, false, {})
     
@@ -630,7 +630,10 @@ function alpha.draw(conf, state)
     layout(conf, state)
     vim.api.nvim_buf_set_option(state.buffer, "modifiable", false)
     local active_win = active_window(state)
-    if vim.api.nvim_get_current_win() == active_win then
+    local active_win_is_valid = active_win and vim.api.nvim_win_is_valid(active_win)
+    local active_win_is_current = active_win == vim.api.nvim_get_current_win()
+
+    if active_win_is_valid and active_win_is_current then
         if #cursor_jumps ~= 0 then
             -- TODO: this is pcalled because a bunch of window events
             -- like WinEnter will say 'alpha' is the current open buffer

In file: https://github.com/goolord/alpha-nvim/blob/main/lua/alpha.lua

I'm happy to hear any suggestions!

@hoofcushion
Copy link
Contributor

hoofcushion commented Feb 25, 2024

Did you use :source to load a session file?
That won't trigger the BufUnload event which is the alpha-nvim used to close its instance.

@goolord
Copy link
Owner

goolord commented Feb 25, 2024

fixed in #267

@goolord goolord closed this as completed Feb 25, 2024
@LiveNL
Copy link
Author

LiveNL commented Feb 26, 2024

Did you use :source to load a session file?

Nope.

Thanks for the update any way! I'll let you know if the issue appears again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants