-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fix lacking space panic #6109
Fix lacking space panic #6109
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the additional saturating subs and defensive clear are definitly correct fixes so this LGTM.
I am not entirely sure if we want to stop returning an optiom required_size
to avoid similar crashes in the future and remove the footgun. That's mostly a code clarity issue tough and can be a separate PR
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
helix-tui/src/buffer.rs
Outdated
if let Some(cell) = self.get_mut(x, y) { | ||
cell.reset(); | ||
cell.set_style(style); | ||
} else { | ||
// Skip this render if the window size has changed | ||
continue; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit wary about changing this: the window size won't change halfway through a render. If clear_with
is called with an out of bounds rectangle then that's a bug that should be addressed and skipping it here would hide the bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a problem with that. Why window can not change it size during render?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a problem with that. Why window can not change it size during render?
The Buffer
is an internal representation of the terminal. Therefore it only changes size if we manually call the resize
method. This is only ever done in the event loop which is "paused" while rendering. So during a render the size of the buffer never changes as @archseer said.
You likely saw crashes here because of the incorrect use of wrapping sub before: #6109 (comment) or the crashed could have been caused by a separate bug that has not been discovered yet.
That being said, it might make more sense to add an assert
at the start of the function1 instead of using the panicing version of the function on every iteration. We could use a debug_assert
. to avoid crashing the editor in daily use Simply clearing less screen is not really a problem until we try to draw on it which would lead to a panic anyway. Cases where we are really just clearing too much screen would not crash the editor this way while still being just as easy to debug.
Footnotes
-
Compilers will not move assets to the start of the function to preserve the order of operations/the work done before the panic. Moving a bounds-check to an explicit assert before a loop is a nice performance optimization and usually more readable while keeping the boundscheck intact. It's used commonly in the std library and I wish more crates would use it too. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the detailed answer. clear_with
is not related with crashes I had indeed.
The idea there is that |
Hmm but size hint also always returns a lower bound and only the upper bound is optional. The value is optional because allocating a larger value is only a performance optimization and never causes a panic, because the implementation can always fallback to the lower bound (which is not optional and just defaults to 0). If I read the code right |
Well now I don't think any bound-check is redundant.
Here's
I think bound-check won't harm readability more than it's absence harms sustainability. |
This is a completly separate bug, totally unrelated to the issue this PR is adressing, It looks like it might be caused caused by a regression in #5420. Please open a separate issue for that. While it might be ok to ignore Please remove the changes to |
I don't understand why |
No it's not ok it is definitely a bug that is why it should panic. The idea is to fail fast and fail hard. If |
Maybe it caused by the window size changing during |
As I said earlier it's impossible for the buffer size to change during rendering , the cause of the crash is a bug somewhere else in the code that should be fixed. If you can find out what caused the crash in |
People can lose unsaved changes due to panic, aren't there ways to keep helix sustainable while not hiding information for debug? Maybe debug code which will be executed in debug build? |
Wait, it does. |
That's what |
Very few people actually use debug builds outside of CI/integration tests yeah. Even locally I only run release builds |
Hmm yeah it does make bug reports harder to track down (see second sentence). I suggested this because we use |
* Fix lack of space for popup crash * Fix saturating -> wrapping * Fix wrapping -> saturating (I am an idiot) * Remove useless "mut" in helix-tui/src/buffer.rs Co-authored-by: Michael Davis <mcarsondavis@gmail.com> * Remove redundant bound-check * Return bound-check back * Add bound-check for set_style * Remove set_style bound-check * Revert bound-check --------- Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
Reincarnation of #5529.
I apologize for the mess around this PR and thank you all for your patience.