Author Topic: Alignment issue (_aligned_malloc) when bpp=32 for surface  (Read 2545 times)

Offline Skybuck

  • Colonel
  • ****
  • Posts: 223
    • View Profile
Alignment issue (_aligned_malloc) when bpp=32 for surface
« on: June 03, 2022, 02:46:37 am »
When surface is set to 32 bits, bpp=32 the following method and code below fails on windows 7 home edition, x64 os:

inline void* NewAligned(int bpp, int width, int height)
{

Code: [Select]

        // of course Windows has to be difficult about this!
buffer = _aligned_malloc(total, 16);
if (!buffer)
{
throw Exception("Failed to allocate surface");
}

It throws some exception.

Why is this alignment necessary ? Is it perhaps an optimization ? (It seems to be related to SSE/Single instruction multiple data ?)

Googling for: sdl aligned buffer

Leads to:

https://wiki.libsdl.org/SDL_SIMDAlloc

Perhaps this is a better method to use ??? Nope: "This function is available since SDL 2.0.10."
« Last Edit: June 03, 2022, 02:51:15 am by Skybuck »