From 5a3672e7a2fd7a89483b97c563fab3091672e8d1 Mon Sep 17 00:00:00 2001 From: Stuart Carnie Date: Mon, 27 Jun 2016 13:20:05 -0700 Subject: [PATCH] ensure buffer is 16-byte aligned (#826) --- src/bgfx_p.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 9b4279bc4..60b53286d 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -2627,8 +2627,9 @@ namespace bgfx uint16_t flags = BGFX_BUFFER_NONE; cmdbuf.write(flags); - tib = (TransientIndexBuffer*)BX_ALLOC(g_allocator, sizeof(TransientIndexBuffer)+_size); - tib->data = (uint8_t*)&tib[1]; + size_t size = BX_ALIGN_16(sizeof(TransientIndexBuffer)) + BX_ALIGN_16(_size); + tib = (TransientIndexBuffer*)BX_ALIGNED_ALLOC(g_allocator, size, 16); + tib->data = (uint8_t *)((size_t)tib + BX_ALIGN_16(sizeof(TransientIndexBuffer))); tib->size = _size; tib->handle = handle; } @@ -2683,8 +2684,9 @@ namespace bgfx uint16_t flags = BGFX_BUFFER_NONE; cmdbuf.write(flags); - tvb = (TransientVertexBuffer*)BX_ALLOC(g_allocator, sizeof(TransientVertexBuffer)+_size); - tvb->data = (uint8_t*)&tvb[1]; + size_t size = BX_ALIGN_16(sizeof(TransientVertexBuffer)) + BX_ALIGN_16(_size); + tvb = (TransientVertexBuffer*)BX_ALIGNED_ALLOC(g_allocator, size, 16); + tvb->data = (uint8_t *)((size_t)tvb + BX_ALIGN_16(sizeof(TransientVertexBuffer))); tvb->size = _size; tvb->startVertex = 0; tvb->stride = stride;