Skip to content

Commit

Permalink
R_FogFactor segfault fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
ouned committed Feb 27, 2016
1 parent 04560fc commit a572eed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/game/q_shared.h
Expand Up @@ -703,6 +703,8 @@ signed short ClampShort( int i );

float q3powf ( float x, int y );

qboolean Q_isnan(float f);

// this isn't a real cheap function to call!
int DirToByte( vec3_t dir );
void ByteToDir( int b, vec3_t dir );
Expand Down
15 changes: 10 additions & 5 deletions src/qcommon/q_math.cpp
Expand Up @@ -2,6 +2,7 @@
//
// q_math.c -- stateless support routines that are included in each code module
#include "../game/q_shared.h"
#include <float.h>


vec3_t vec3_origin = {0,0,0};
Expand Down Expand Up @@ -546,11 +547,7 @@ float Q_rsqrt( float number )
y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
// y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed

#ifndef Q3_VM
#ifdef __linux__
assert( !isnan(y) ); // bk010122 - FPE?
#endif
#endif
assert(!Q_isnan(y));
return y;
}

Expand Down Expand Up @@ -1036,3 +1033,11 @@ float q3powf ( float x, int y )
r = r * r;
return r;
}

qboolean Q_isnan(float f) {
#ifdef _WIN32
return (qboolean)(_isnan(f) != 0);
#else
return (qboolean)(isnan(f) != 0);
#endif
}
4 changes: 2 additions & 2 deletions src/renderer/tr_shade_calc.cpp
Expand Up @@ -904,8 +904,8 @@ void RB_CalcFogTexCoords( float *st ) {
}
}

st[0] = s;
st[1] = t;
st[0] = Q_isnan(s) ? 0.0f : s;
st[1] = Q_isnan(s) ? 0.0f : t;
st += 2;
}
}
Expand Down

0 comments on commit a572eed

Please sign in to comment.