Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
Ensure enough alignment for IImages
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Mar 10, 2024
1 parent 9d07f90 commit 26c4f4e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions source/Irrlicht/CImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ CImage::CImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& 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<u8*>(new u32[allocSize / 4]);
memcpy(Data, data, dataSize);
DeleteMemory = true;
}
Expand All @@ -36,7 +38,10 @@ CImage::CImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& size, void* d
//! Constructor of empty image
CImage::CImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& 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<u8*>(new u32[allocSize / 4]);
DeleteMemory = true;
}

Expand Down

0 comments on commit 26c4f4e

Please sign in to comment.