Invalid buffer id-errors
Opened this issue · 3 comments
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.
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!
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.
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.