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.
Part of #748.
This PR mitigates the unsoundness caused by the
Image
fields being public and adds new safe methods for immutable access and unsafe methods for mutable access. The second commit changes all usages of these fields within macroquad itself to the new methods.The reason for this unsoundness is that
Image::get_image_data
relies on the invariant thatwidth * height == bytes.len()
to efficiently convert the image bytes into a color slice.Fixes #634.
Fixes #746.
New methods
Image::from_parts
: method for creating an image from width, height and bytes while checking if the amount of bytes is correctImage::bytes
,Image::bytes_mut
: returns an immutable / mutable slice of all bytes in the imageImage::width_mut
,Image::height_mut
,Image::bytes_vec_mut
: unsafe methods that return a mutable reference to the respective field, allowing for unchecked manipulation (mostly exist to support migration of strange usecases)Other non-breaking changes
Image
fields directly gives a deprecation warning and suggests using the methods instead.