From 27b955ed8aae71e0a4a15d75e1c06ffa6516fbe5 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Fri, 16 Oct 2015 19:18:38 -0500 Subject: Fix not swapping buffers because out of cmd buffer space Reserve space for end of list and swap buffer commands. These are absolutely required and cannot be dropped. Dropping swap buffer command causes screen to not update and possible crash from drawsurf buffer overflow if not enough cmd buffer space for many continous frames. --- src/renderergl1/tr_cmds.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/renderergl1/tr_cmds.c') diff --git a/src/renderergl1/tr_cmds.c b/src/renderergl1/tr_cmds.c index 23aa9897..0ff7faee 100644 --- a/src/renderergl1/tr_cmds.c +++ b/src/renderergl1/tr_cmds.c @@ -115,19 +115,19 @@ void R_IssuePendingRenderCommands( void ) { /* ============ -R_GetCommandBuffer +R_GetCommandBufferReserved make sure there is enough command space ============ */ -void *R_GetCommandBuffer( int bytes ) { +void *R_GetCommandBufferReserved( int bytes, int reservedBytes ) { renderCommandList_t *cmdList; cmdList = &backEndData->commands; bytes = PAD(bytes, sizeof(void *)); // always leave room for the end of list command - if ( cmdList->used + bytes + 4 > MAX_RENDER_COMMANDS ) { + if ( cmdList->used + bytes + 4 + reservedBytes > MAX_RENDER_COMMANDS ) { if ( bytes > MAX_RENDER_COMMANDS - 4 ) { ri.Error( ERR_FATAL, "R_GetCommandBuffer: bad size %i", bytes ); } @@ -140,6 +140,17 @@ void *R_GetCommandBuffer( int bytes ) { return cmdList->cmds + cmdList->used - bytes; } +/* +============= +R_GetCommandBuffer + +returns NULL if there is not enough space for important commands +============= +*/ +void *R_GetCommandBuffer( int bytes ) { + return R_GetCommandBufferReserved( bytes, sizeof ( swapBuffersCommand_t ) ); +} + /* ============= @@ -540,7 +551,7 @@ void RE_EndFrame( int *frontEndMsec, int *backEndMsec ) { if ( !tr.registered ) { return; } - cmd = R_GetCommandBuffer( sizeof( *cmd ) ); + cmd = R_GetCommandBufferReserved( sizeof( *cmd ), 0 ); if ( !cmd ) { return; } -- cgit From 6c232efd91fd288342bc6865a36fa1c8c0a23575 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Fri, 16 Oct 2015 20:50:25 -0500 Subject: Fix reserved size for swap buffer command being too small on x86_64 --- src/renderergl1/tr_cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/renderergl1/tr_cmds.c') diff --git a/src/renderergl1/tr_cmds.c b/src/renderergl1/tr_cmds.c index 0ff7faee..58f199e3 100644 --- a/src/renderergl1/tr_cmds.c +++ b/src/renderergl1/tr_cmds.c @@ -148,7 +148,7 @@ returns NULL if there is not enough space for important commands ============= */ void *R_GetCommandBuffer( int bytes ) { - return R_GetCommandBufferReserved( bytes, sizeof ( swapBuffersCommand_t ) ); + return R_GetCommandBufferReserved( bytes, PAD( sizeof( swapBuffersCommand_t ), sizeof(void *) ) ); } -- cgit From 802eb6dfaffb6efba11705fcce16eed8a6e34bad Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Sat, 17 Oct 2015 21:57:16 -0500 Subject: Replace 4 with sizeof( int ) in R_GetCommandBufferReserved --- src/renderergl1/tr_cmds.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/renderergl1/tr_cmds.c') diff --git a/src/renderergl1/tr_cmds.c b/src/renderergl1/tr_cmds.c index 58f199e3..d92a8b94 100644 --- a/src/renderergl1/tr_cmds.c +++ b/src/renderergl1/tr_cmds.c @@ -127,8 +127,8 @@ void *R_GetCommandBufferReserved( int bytes, int reservedBytes ) { bytes = PAD(bytes, sizeof(void *)); // always leave room for the end of list command - if ( cmdList->used + bytes + 4 + reservedBytes > MAX_RENDER_COMMANDS ) { - if ( bytes > MAX_RENDER_COMMANDS - 4 ) { + if ( cmdList->used + bytes + sizeof( int ) + reservedBytes > MAX_RENDER_COMMANDS ) { + if ( bytes > MAX_RENDER_COMMANDS - sizeof( int ) ) { ri.Error( ERR_FATAL, "R_GetCommandBuffer: bad size %i", bytes ); } // if we run out of room, just start dropping commands -- cgit