From 6693bcabafb81a019c4c3a457357d154ca91a0ad Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Sun, 8 May 2011 17:58:56 -0400 Subject: [PATCH] Eliminate an unaligned pointer in renderer Signed-off-by: Matt Turner --- code/renderer/tr_backend.c | 2 ++ code/renderer/tr_cmds.c | 1 + code/renderer/tr_local.h | 1 + code/renderer/tr_shader.c | 2 ++ 4 files changed, 6 insertions(+), 0 deletions(-) diff --git a/code/renderer/tr_backend.c b/code/renderer/tr_backend.c index 30c9368..9c6df65 100644 --- a/code/renderer/tr_backend.c +++ b/code/renderer/tr_backend.c @@ -1142,6 +1142,8 @@ void RB_ExecuteRenderCommands( const void *data ) { } while ( 1 ) { + data = (const void *)ALIGN((intptr_t)data, sizeof(void *)); + switch ( *(const int *)data ) { case RC_SET_COLOR: data = RB_SetColor( data ); diff --git a/code/renderer/tr_cmds.c b/code/renderer/tr_cmds.c index 108299c..c169e9d 100644 --- a/code/renderer/tr_cmds.c +++ b/code/renderer/tr_cmds.c @@ -195,6 +195,7 @@ void *R_GetCommandBuffer( int bytes ) { renderCommandList_t *cmdList; cmdList = &backEndData[tr.smpFrame]->commands; + bytes = ALIGN(bytes, sizeof(void *)); // always leave room for the end of list command if ( cmdList->used + bytes + 4 > MAX_RENDER_COMMANDS ) { diff --git a/code/renderer/tr_local.h b/code/renderer/tr_local.h index 93c4bae..eeba631 100644 --- a/code/renderer/tr_local.h +++ b/code/renderer/tr_local.h @@ -41,6 +41,7 @@ long myftol( float f ); #define myftol(x) ((int)(x)) #endif +#define ALIGN(value, alignment) (((value) + alignment - 1) & ~(alignment - 1)) // everything that is needed by the backend needs // to be double buffered to allow it to run in diff --git a/code/renderer/tr_shader.c b/code/renderer/tr_shader.c index a88ba2b..660c3ce 100644 --- a/code/renderer/tr_shader.c +++ b/code/renderer/tr_shader.c @@ -1878,6 +1878,8 @@ static void FixRenderCommandList( int newShader ) { const void *curCmd = cmdList->cmds; while ( 1 ) { + curCmd = (const void *)ALIGN((intptr_t)curCmd, sizeof(void *)); + switch ( *(const int *)curCmd ) { case RC_SET_COLOR: { -- 1.7.3.4