mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-12 02:02:20 +00:00
* fix: eliminate UB in read_pixels_of_type via bytemuck::cast_slice The previous implementation used Vec::from_raw_parts to reinterpret a Vec<u8> as Vec<T>, then mem::forget to suppress the original Vec's destructor. This was UB for two reasons: 1. mem::forget receives an invalid value (already-transferred ownership) 2. Vec<T> deallocates with align_of::<T>(), but the memory was allocated with align_of::<u8>() = 1, violating alloc/dealloc layout invariants Replace with bytemuck::cast_slice + to_vec(), which safely casts the byte slice and copies into a properly-aligned Vec<T>. The Pod bound already guarantees valid bit patterns for any byte sequence. Closes #827 * fix: zero-copy TypedPixels<T> wrapper preserves original byte layout Per @mrDIMAS review: avoid the .to_vec() copy by introducing a TypedPixels<T> proxy struct that owns the original Vec<u8> (preserving its allocation layout for correct deallocation) and exposes &[T] via Deref + bytemuck::cast_slice. Mirrors the BytesStorage pattern used in fyrox-impl/src/scene/mesh/buffer.rs. The single caller (HDR luminance histogram) uses &pixels as a slice, which works unchanged via deref coercion.