fix(messages): prevent msg_scroll_flush() asserts during screen resize (#31002, #22919) #36810
+43
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes #31002 #22919 and possibly a class of crashes triggered when msg_scroll_flush() is called during a screen resize.
The root cause of the crashes is that msg_scroll_flush() assumes that the message layout state is consistent with the current geometry, however, during screen_resize() this assumption is invalid:
The resize operation updates geometry in several steps, screen_resize() triggers VimResized autocmds before the resize is finished, those autocmds may execute :redraw,
screenstring(), and any other function that calls into the UI layer.These paths eventually call msg_scroll_flush(), but the message grid is still using stale positions and offsets, Which may triggers the following asserts:
row >= 0 (reproducible)
pos_delta >= 0 ( not always reproducible see chat on issue #32319)
to_scroll >= 0 ( not always reproducible see chat on issue #22919)
while trying to fix these issues I was placing several if statement, in different locations in the codebase, when i realized
that it could be safer, and a lot cleaner to make msg_scroll_flush() a no-op while the screen is resizing:
This ensures:
and once the resize completes,
msg_grid_set_pos(),compute_cmdrow(),update_screen(),msg_grid_validate()recompute the correct message layout, and normal scrolling resumes safely.