From d9fd8dc29fb30b6a76136c5c2fa5d9edb8fa7c13 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 27 Oct 2001 08:31:45 +0000 Subject: [PATCH] make r_particles truely a flag and call R_MaxParticlesCheck when r_particles changes --- libs/video/renderer/r_cvar.c | 5 ++++- libs/video/renderer/r_part.c | 23 +++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/libs/video/renderer/r_cvar.c b/libs/video/renderer/r_cvar.c index 5601eeb16..0776a3a45 100644 --- a/libs/video/renderer/r_cvar.c +++ b/libs/video/renderer/r_cvar.c @@ -141,8 +141,11 @@ r_particles_f (cvar_t *var) { if (!var->int_val) R_ClearParticles (); + r_maxparticles = 0; + if (var->int_val && cl_max_particles) + r_maxparticles = cl_max_particles->int_val; if (cl_max_particles) - r_maxparticles = var->int_val * cl_max_particles->int_val; + R_MaxParticlesCheck (cl_max_particles); } void diff --git a/libs/video/renderer/r_part.c b/libs/video/renderer/r_part.c index 582cfa2f7..cc728b25e 100644 --- a/libs/video/renderer/r_part.c +++ b/libs/video/renderer/r_part.c @@ -65,21 +65,28 @@ R_MaxParticlesCheck (cvar_t *var) Prevents a segfault since if we grabbed the int_val of cl_max_particles we'd sig11 right here at startup. */ - if (r_particles) - r_maxparticles = max(var->int_val * r_particles->int_val, 0); + if (r_particles && r_particles->int_val) + r_maxparticles = var->int_val; else - r_maxparticles = max(var->int_val, 0); + r_maxparticles = 0; /* Be very careful the next time we do something like this. calloc/free are IMPORTANT and the compiler doesn't know when we do bad things with them. */ - free (particles); - free (freeparticles); + if (particles) + free (particles); + if (freeparticles) + free (freeparticles); - particles = (particle_t *) calloc (r_maxparticles, sizeof (particle_t)); - freeparticles = (particle_t **) calloc (r_maxparticles, - sizeof (particle_t *)); + particles = 0; + freeparticles = 0; + + if (r_maxparticles) { + particles = (particle_t *) calloc (r_maxparticles, sizeof (particle_t)); + freeparticles = (particle_t **) calloc (r_maxparticles, + sizeof (particle_t *)); + } R_ClearParticles(); }