Open
Conversation
That the buffer is zeroed when `age == 0` is not guaranteed, e.g. on many platforms (Wayland, X11, Web), when we resize the buffer, we don't also clear it. We could technically guarantee something like "if the buffer's underlying data could not be reused, the buffer is zero-initialized", but that's not really useful to users (at least not unless we expose additional information in `Buffer::age`). This might also make it easier to use zero-copying on Android (might be able to avoid having to clear the buffer).
To help make it clear that the buffer isn't zero-initialize / catch
mistakes where the user was relying on it.
For example, drawing like this is incorrect:
```
// Fill with blue.
for (_, _, pixel) in buffer.pixels_iter() {
pixel.b = 0xff;
pixel.a = 0xff;
}
```
Member
Author
|
Note that zero-initializing might have been useful in the past, because it corresponded to black, but it isn't really useful after #321, after that we panic when |
notgull
approved these changes
Mar 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
That the buffer is zeroed when
age == 0is not guaranteed, e.g. on many platforms (Wayland, X11, Web), when we resize the buffer, we don't also clear it.We could technically guarantee something like "if the buffer's underlying data could not be reused, the buffer is zero-initialized", but that's not really useful to users (at least not unless we expose additional information in
Buffer::age).This might also make it easier to use zero-copying on Android (might be able to avoid having to clear the buffer if we can prove that the
MaybeUninitis actually initialized), see discussion in #331 (comment).To help a bit with catching mistakes like this in the future / documenting the state of affairs in the code, I've added a private
Pixel::INITwhich most backends initialize their buffers with.