Skip to content

Commit 3651883

Browse files
committed
tr_model_iqm: rewrite NaN in model IQM input
1 parent 80821bf commit 3651883

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

src/engine/renderer/tr_model_iqm.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,23 @@ BuildTangents
415415
Compute Tangent and Bitangent vectors from the IQM 4-float input data
416416
=================
417417
*/
418-
void BuildTangents( int n, float *input, float *normals, float *tangents,
418+
static bool BuildTangents( int n, float *input, float *normals, float *tangents,
419419
float *bitangents )
420420
{
421-
int i;
422-
vec3_t crossProd;
421+
bool finite = true;
423422

424-
for( i = 0; i < n; i++ ) {
423+
for ( int i = 0; i < n; i++ ) {
424+
for ( int j = 0; j < 4; j++ )
425+
{
426+
if ( !Math::IsFinite( input[ j ] ) )
427+
{
428+
Log::Warn("IQM model input[%d][%d] is NaN.", i, j);
429+
input[ j ] = 0.0f;
430+
finite = false;
431+
}
432+
}
433+
434+
vec3_t crossProd;
425435
VectorCopy( input, tangents );
426436
CrossProduct( normals, input, crossProd );
427437
VectorScale( crossProd, input[ 3 ], bitangents );
@@ -431,6 +441,8 @@ void BuildTangents( int n, float *input, float *normals, float *tangents,
431441
tangents += 3;
432442
bitangents += 3;
433443
}
444+
445+
return finite;
434446
}
435447

436448
/*
@@ -718,10 +730,17 @@ bool R_LoadIQModel( model_t *mod, const void *buffer, int filesize,
718730
n * sizeof(float) );
719731
break;
720732
case IQM_TANGENT:
721-
BuildTangents( header->num_vertexes,
722-
( float* )IQMPtr( header, vertexarray->offset ),
723-
IQModel->normals, IQModel->tangents,
724-
IQModel->bitangents );
733+
{
734+
bool finite = BuildTangents( header->num_vertexes,
735+
( float* )IQMPtr( header, vertexarray->offset ),
736+
IQModel->normals, IQModel->tangents,
737+
IQModel->bitangents );
738+
739+
if ( !finite )
740+
{
741+
Log::Warn( "Model %s contains NaN input.", mod_name );
742+
}
743+
}
725744
break;
726745
case IQM_TEXCOORD:
727746
for( int j = 0; j < n; j++ ) {

0 commit comments

Comments
 (0)