From 26c4f4e63d2e7fd30c0d0d6d8ebbbaddbaa15364 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 10 Mar 2024 13:57:48 +0100 Subject: [PATCH] Ensure enough alignment for IImages --- source/Irrlicht/CImage.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/source/Irrlicht/CImage.cpp b/source/Irrlicht/CImage.cpp index c4fd3a2e3..dee8962d5 100644 --- a/source/Irrlicht/CImage.cpp +++ b/source/Irrlicht/CImage.cpp @@ -25,8 +25,10 @@ CImage::CImage(ECOLOR_FORMAT format, const core::dimension2d& size, void* d else { const u32 dataSize = getDataSizeFromFormat(Format, Size.Width, Size.Height); + const u32 allocSize = align_next(dataSize, 16); - Data = new u8[align_next(dataSize,16)]; + // allocate as u32 to ensure enough alignment when casted + Data = reinterpret_cast(new u32[allocSize / 4]); memcpy(Data, data, dataSize); DeleteMemory = true; } @@ -36,7 +38,10 @@ CImage::CImage(ECOLOR_FORMAT format, const core::dimension2d& size, void* d //! Constructor of empty image CImage::CImage(ECOLOR_FORMAT format, const core::dimension2d& size) : IImage(format, size, true) { - Data = new u8[align_next(getDataSizeFromFormat(Format, Size.Width, Size.Height),16)]; + const u32 dataSize = getDataSizeFromFormat(Format, Size.Width, Size.Height); + const u32 allocSize = align_next(dataSize, 16); + + Data = reinterpret_cast(new u32[allocSize / 4]); DeleteMemory = true; }