mirror of
https://github.com/bkaradzic/bimg.git
synced 2026-02-17 20:52:38 +01:00
Fixed memory alignment.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
#include <stdint.h> // uint32_t
|
||||
#include <stdlib.h> // NULL
|
||||
|
||||
#define BIMG_API_VERSION UINT32_C(5)
|
||||
#define BIMG_API_VERSION UINT32_C(6)
|
||||
|
||||
namespace bx
|
||||
{
|
||||
|
||||
@@ -2891,10 +2891,10 @@ namespace bimg
|
||||
const uint8_t numMips = _hasMips ? imageGetNumMips(_format, _width, _height, _depth) : 1;
|
||||
uint32_t size = imageGetSize(NULL, _width, _height, _depth, _cubeMap, _hasMips, _numLayers, _format);
|
||||
|
||||
ImageContainer* imageContainer = (ImageContainer*)BX_ALLOC(_allocator, size + sizeof(ImageContainer) );
|
||||
ImageContainer* imageContainer = (ImageContainer*)BX_ALLOC(_allocator, size + BX_ALIGN_16(sizeof(ImageContainer) ) );
|
||||
|
||||
imageContainer->m_allocator = _allocator;
|
||||
imageContainer->m_data = imageContainer + 1;
|
||||
imageContainer->m_data = bx::alignPtr(imageContainer + 1, 0, 16);
|
||||
imageContainer->m_format = _format;
|
||||
imageContainer->m_orientation = Orientation::R0;
|
||||
imageContainer->m_size = size;
|
||||
|
||||
@@ -796,6 +796,30 @@ void help(const char* _str, const bx::Error& _err)
|
||||
help(str.c_str(), false);
|
||||
}
|
||||
|
||||
class AlignedAllocator : public bx::AllocatorI
|
||||
{
|
||||
public:
|
||||
AlignedAllocator(bx::AllocatorI* _allocator, size_t _minAlignment)
|
||||
: m_allocator(_allocator)
|
||||
, m_minAlignment(_minAlignment)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void* realloc(
|
||||
void* _ptr
|
||||
, size_t _size
|
||||
, size_t _align
|
||||
, const char* _file
|
||||
, uint32_t _line
|
||||
)
|
||||
{
|
||||
return m_allocator->realloc(_ptr, _size, bx::max(_align, m_minAlignment), _file, _line);
|
||||
}
|
||||
|
||||
bx::AllocatorI* m_allocator;
|
||||
size_t m_minAlignment;
|
||||
};
|
||||
|
||||
int main(int _argc, const char* _argv[])
|
||||
{
|
||||
bx::CommandLine cmdLine(_argc, _argv);
|
||||
@@ -947,7 +971,9 @@ int main(int _argc, const char* _argv[])
|
||||
return bx::kExitFailure;
|
||||
}
|
||||
|
||||
bx::DefaultAllocator allocator;
|
||||
bx::DefaultAllocator defaultAllocator;
|
||||
AlignedAllocator allocator(&defaultAllocator, 16);
|
||||
|
||||
uint8_t* inputData = (uint8_t*)BX_ALLOC(&allocator, inputSize);
|
||||
|
||||
bx::read(&reader, inputData, inputSize, &err);
|
||||
|
||||
Reference in New Issue
Block a user