From e3465d5a891b2844e271c54550c7cb97d81b4a7f Mon Sep 17 00:00:00 2001 From: hgn Date: Mon, 26 Dec 2022 15:39:25 +0000 Subject: [PATCH] enforce alignment --- submodules/SDL | 2 +- vg.h | 2 +- vg_audio.h | 2 +- vg_mem.h | 12 ++++++++++++ vg_ui.h | 2 +- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/submodules/SDL b/submodules/SDL index eef4d3c..06492c5 160000 --- a/submodules/SDL +++ b/submodules/SDL @@ -1 +1 @@ -Subproject commit eef4d3c86a653f91b7221c80809ba8ab56f94cf1 +Subproject commit 06492c598158cf825a18aececaf7511d7fd04f48 diff --git a/vg.h b/vg.h index 1945b82..ada5469 100644 --- a/vg.h +++ b/vg.h @@ -626,7 +626,7 @@ VG_STATIC void _vg_process_launch_opts_internal( int argc, char *argv[] ) if( vg_long_opt( "use-libc-malloc" ) ) { - vg_mem.use_libc_malloc = atoi( arg ); + vg_mem.use_libc_malloc = 1; } if( vg_long_opt( "high-performance" ) ) diff --git a/vg_audio.h b/vg_audio.h index fc09d10..aeb05a4 100644 --- a/vg_audio.h +++ b/vg_audio.h @@ -816,7 +816,7 @@ VG_STATIC void audio_clip_load( audio_clip *clip, void *lin_alloc ) data_size = length_samples * sizeof(i16); audio_lock(); - clip->data = vg_linear_alloc( lin_alloc, data_size ); + clip->data = vg_linear_alloc( lin_alloc, vg_align8(data_size) ); clip->size = length_samples; audio_unlock(); diff --git a/vg_mem.h b/vg_mem.h index 3a7a49d..a214674 100644 --- a/vg_mem.h +++ b/vg_mem.h @@ -90,6 +90,12 @@ VG_STATIC void vg_fatal_exit_loop( const char *error ); VG_STATIC void vg_error(const char *fmt, ...); VG_STATIC void vg_info(const char *fmt, ...); +VG_STATIC u32 vg_align8( u32 s ) +{ + u32 m = (s + 7) >> 3; + return m << 3; +} + /* Returns allocator structure from data pointer */ static vg_linear_allocator *vg_linear_header( void *data ) { @@ -103,6 +109,12 @@ static vg_linear_allocator *vg_linear_header( void *data ) __attribute__((warn_unused_result)) VG_STATIC void *vg_linear_alloc( void *buffer, u32 size ) { + if( size % 8 ) + { + vg_error( "Requested size: %u\n", size ); + vg_fatal_exit_loop( "8 byte alignment required" ); + } + vg_linear_allocator *alloc = vg_linear_header( buffer ); if( (alloc->cur + size) > alloc->size ) diff --git a/vg_ui.h b/vg_ui.h index 8e73da5..0c88b2f 100644 --- a/vg_ui.h +++ b/vg_ui.h @@ -227,7 +227,7 @@ VG_STATIC void _vg_ui_init(void) /* Alloc RAM default context */ u32 vert_size = vg_uictx.max_verts*sizeof(struct ui_vert), - inds_size = vg_uictx.max_indices*sizeof(u16); + inds_size = vg_align8( vg_uictx.max_indices*sizeof(u16) ); vg_uictx.vertex_buffer = vg_linear_alloc( vg_mem.rtmemory, vert_size ); vg_uictx.indice_buffer = vg_linear_alloc( vg_mem.rtmemory, inds_size ); -- 2.25.1