Skip to content

Commit a7bf7c6

Browse files
committed
Merge pull request #490 from Goober5000/shipfx_little_explosions_fix
for model vertices, use the entire range of RAND_MAX, not the range divided by 32
2 parents 47286d1 + 81676b7 commit a7bf7c6

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

code/model/modelinterp.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3603,8 +3603,21 @@ void submodel_get_two_random_points(int model_num, int submodel_num, vec3d *v1,
36033603
return;
36043604
}
36053605

3606-
int vn1 = (myrand()>>5) % nv;
3607-
int vn2 = (myrand()>>5) % nv;
3606+
#ifndef NDEBUG
3607+
if (RAND_MAX < nv)
3608+
{
3609+
static int submodel_get_two_random_points_warned = false;
3610+
if (!submodel_get_two_random_points_warned)
3611+
{
3612+
polymodel *pm = model_get(model_num);
3613+
Warning(LOCATION, "RAND_MAX is only %d, but submodel %d for model %s has %d vertices! Explosions will not propagate through the entire model!\n", RAND_MAX, submodel_num, pm->filename, nv);
3614+
submodel_get_two_random_points_warned = true;
3615+
}
3616+
}
3617+
#endif
3618+
3619+
int vn1 = myrand() % nv;
3620+
int vn2 = myrand() % nv;
36083621

36093622
*v1 = *Interp_verts[vn1];
36103623
*v2 = *Interp_verts[vn2];
@@ -3641,9 +3654,20 @@ void submodel_get_two_random_points_better(int model_num, int submodel_num, vec3
36413654
return;
36423655
}
36433656

3644-
Assert(nv > 0); // Goober5000 - to avoid div-0 error
3645-
int vn1 = (myrand()>>5) % nv;
3646-
int vn2 = (myrand()>>5) % nv;
3657+
#ifndef NDEBUG
3658+
if (RAND_MAX < nv)
3659+
{
3660+
static int submodel_get_two_random_points_warned = false;
3661+
if (!submodel_get_two_random_points_warned)
3662+
{
3663+
Warning(LOCATION, "RAND_MAX is only %d, but submodel %d for model %s has %d vertices! Explosions will not propagate through the entire model!\n", RAND_MAX, submodel_num, pm->filename, nv);
3664+
submodel_get_two_random_points_warned = true;
3665+
}
3666+
}
3667+
#endif
3668+
3669+
int vn1 = myrand() % nv;
3670+
int vn2 = myrand() % nv;
36473671

36483672
*v1 = tree->point_list[vn1];
36493673
*v2 = tree->point_list[vn2];

0 commit comments

Comments
 (0)