From aa2ea68741f913b861c8e7ce6f0ac07a71c1f36a Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Tue, 18 Jun 2013 18:00:45 -0500 Subject: [PATCH] Fix IQM tess buffer overflow Set the variables that use tess.numVertexes after calling RB_CHECKOVERFLOW() as it may set tess.numVertexes to 0! Could cause visual issues and error "RB_EndSurface() - SHADER_MAX_VERTEXES hit". --- code/renderergl1/tr_model_iqm.c | 13 +++++++++---- code/renderergl2/tr_model_iqm.c | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/code/renderergl1/tr_model_iqm.c b/code/renderergl1/tr_model_iqm.c index 0c7d4665..a0cdbe75 100644 --- a/code/renderergl1/tr_model_iqm.c +++ b/code/renderergl1/tr_model_iqm.c @@ -953,10 +953,10 @@ void RB_IQMSurfaceAnim( surfaceType_t *surface ) { float jointMats[IQM_MAX_JOINTS * 12]; int i; - vec4_t *outXYZ = &tess.xyz[tess.numVertexes]; - vec4_t *outNormal = &tess.normal[tess.numVertexes]; - vec2_t (*outTexCoord)[2] = &tess.texCoords[tess.numVertexes]; - color4ub_t *outColor = &tess.vertexColors[tess.numVertexes]; + vec4_t *outXYZ; + vec4_t *outNormal; + vec2_t (*outTexCoord)[2]; + color4ub_t *outColor; int frame = data->num_frames ? backEnd.currentEntity->e.frame % data->num_frames : 0; int oldframe = data->num_frames ? backEnd.currentEntity->e.oldframe % data->num_frames : 0; @@ -968,6 +968,11 @@ void RB_IQMSurfaceAnim( surfaceType_t *surface ) { RB_CHECKOVERFLOW( surf->num_vertexes, surf->num_triangles * 3 ); + outXYZ = &tess.xyz[tess.numVertexes]; + outNormal = &tess.normal[tess.numVertexes]; + outTexCoord = &tess.texCoords[tess.numVertexes]; + outColor = &tess.vertexColors[tess.numVertexes]; + // compute interpolated joint matrices if ( data->num_joints > 0 ) { ComputePoseMats( data, frame, oldframe, backlerp, jointMats ); diff --git a/code/renderergl2/tr_model_iqm.c b/code/renderergl2/tr_model_iqm.c index 43dece19..30b8ff07 100644 --- a/code/renderergl2/tr_model_iqm.c +++ b/code/renderergl2/tr_model_iqm.c @@ -953,10 +953,10 @@ void RB_IQMSurfaceAnim( surfaceType_t *surface ) { float jointMats[IQM_MAX_JOINTS * 12]; int i; - vec4_t *outXYZ = &tess.xyz[tess.numVertexes]; - vec4_t *outNormal = &tess.normal[tess.numVertexes]; - vec2_t (*outTexCoord)[2] = &tess.texCoords[tess.numVertexes]; - vec4_t *outColor = &tess.vertexColors[tess.numVertexes]; + vec4_t *outXYZ; + vec4_t *outNormal; + vec2_t (*outTexCoord)[2]; + vec4_t *outColor; int frame = data->num_frames ? backEnd.currentEntity->e.frame % data->num_frames : 0; int oldframe = data->num_frames ? backEnd.currentEntity->e.oldframe % data->num_frames : 0; @@ -968,6 +968,11 @@ void RB_IQMSurfaceAnim( surfaceType_t *surface ) { RB_CHECKOVERFLOW( surf->num_vertexes, surf->num_triangles * 3 ); + outXYZ = &tess.xyz[tess.numVertexes]; + outNormal = &tess.normal[tess.numVertexes]; + outTexCoord = &tess.texCoords[tess.numVertexes]; + outColor = &tess.vertexColors[tess.numVertexes]; + // compute interpolated joint matrices if ( data->num_joints > 0 ) { ComputePoseMats( data, frame, oldframe, backlerp, jointMats );