Skip to content

Commit a572eed

Browse files
committed
R_FogFactor segfault fixed
JACoders/OpenJK@efc56dd
1 parent 04560fc commit a572eed

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/game/q_shared.h

+2
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,8 @@ signed short ClampShort( int i );
703703

704704
float q3powf ( float x, int y );
705705

706+
qboolean Q_isnan(float f);
707+
706708
// this isn't a real cheap function to call!
707709
int DirToByte( vec3_t dir );
708710
void ByteToDir( int b, vec3_t dir );

src/qcommon/q_math.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//
33
// q_math.c -- stateless support routines that are included in each code module
44
#include "../game/q_shared.h"
5+
#include <float.h>
56

67

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

549-
#ifndef Q3_VM
550-
#ifdef __linux__
551-
assert( !isnan(y) ); // bk010122 - FPE?
552-
#endif
553-
#endif
550+
assert(!Q_isnan(y));
554551
return y;
555552
}
556553

@@ -1036,3 +1033,11 @@ float q3powf ( float x, int y )
10361033
r = r * r;
10371034
return r;
10381035
}
1036+
1037+
qboolean Q_isnan(float f) {
1038+
#ifdef _WIN32
1039+
return (qboolean)(_isnan(f) != 0);
1040+
#else
1041+
return (qboolean)(isnan(f) != 0);
1042+
#endif
1043+
}

src/renderer/tr_shade_calc.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -904,8 +904,8 @@ void RB_CalcFogTexCoords( float *st ) {
904904
}
905905
}
906906

907-
st[0] = s;
908-
st[1] = t;
907+
st[0] = Q_isnan(s) ? 0.0f : s;
908+
st[1] = Q_isnan(s) ? 0.0f : t;
909909
st += 2;
910910
}
911911
}

0 commit comments

Comments
 (0)