From: divverent Date: Thu, 11 Oct 2007 22:08:05 +0000 (+0000) Subject: - fix SEGFAULT when a .shader file has more layers than allowed X-Git-Tag: xonotic-v0.1.0preview~2850 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=3b725b70c7c7bf9bc5de6b5d1b60609c536167e8;p=xonotic%2Fdarkplaces.git - fix SEGFAULT when a .shader file has more layers than allowed - reduce number of layers from 8 to 2 to save memory (increase it later when additional layers are actually USED) - parse ALL layers, even those behind the limit, to check for lightmap references and similar stuff - when looking up a shader, only look through the actually DEFINED layers (not through all ALLOCATED ones), this means that the OS won't allocate pages more shaders than actually used - increase maximum number of tcmods from 4 to 8 for Nexuiz net: 1300MB -> 900MB vsize, and less RSS used too; so it won't swap any more on a 1GB system git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7630 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/model_shared.c b/model_shared.c index 7266fe6c..880d5f3f 100644 --- a/model_shared.c +++ b/model_shared.c @@ -1153,25 +1153,28 @@ void Mod_LoadQ3Shaders(void) break; if (!strcasecmp(com_token, "{")) { + static q3shaderinfo_layer_t dummy; if (shader->numlayers < Q3SHADER_MAXLAYERS) { layer = shader->layers + shader->numlayers++; - layer->rgbgen.rgbgen = Q3RGBGEN_IDENTITY; - layer->alphagen.alphagen = Q3ALPHAGEN_IDENTITY; - layer->tcgen.tcgen = Q3TCGEN_TEXTURE; - layer->blendfunc[0] = GL_ONE; - layer->blendfunc[1] = GL_ZERO; } else - layer = NULL; + { + // parse and process it anyway, just don't store it (so a map $lightmap or such stuff still is found) + memset(&dummy, 0, sizeof(dummy)); + layer = &dummy; + } + layer->rgbgen.rgbgen = Q3RGBGEN_IDENTITY; + layer->alphagen.alphagen = Q3ALPHAGEN_IDENTITY; + layer->tcgen.tcgen = Q3TCGEN_TEXTURE; + layer->blendfunc[0] = GL_ONE; + layer->blendfunc[1] = GL_ZERO; while (COM_ParseToken_QuakeC(&text, false)) { if (!strcasecmp(com_token, "}")) break; if (!strcasecmp(com_token, "\n")) continue; - if (layer == NULL) - continue; numparameters = 0; for (j = 0;strcasecmp(com_token, "\n") && strcasecmp(com_token, "}");j++) { @@ -1359,7 +1362,7 @@ void Mod_LoadQ3Shaders(void) else Con_DPrintf("%s parsing warning: too many tcmods on one layer\n", search->filenames[fileindex]); } - // break out a level if it was } + // break out a level if it was a closing brace (not using the character here to not confuse vim) if (!strcasecmp(com_token, "}")) break; } @@ -1590,7 +1593,7 @@ void Mod_LoadQ3Shaders(void) q3shaderinfo_t *Mod_LookupQ3Shader(const char *name) { int i; - for (i = 0;i < Q3SHADER_MAXSHADERS;i++) + for (i = 0;i < q3shaders_numshaders;i++) if (!strcasecmp(q3shaders_shaders[i].name, name)) return q3shaders_shaders + i; return NULL; diff --git a/model_shared.h b/model_shared.h index c254424a..058073fd 100644 --- a/model_shared.h +++ b/model_shared.h @@ -194,12 +194,12 @@ shadowmesh_t; #define TEXTURE_MAXFRAMES 64 #define Q3WAVEPARMS 4 #define Q3DEFORM_MAXPARMS 3 -#define Q3SHADER_MAXLAYERS 8 +#define Q3SHADER_MAXLAYERS 2 // FIXME support more than that (currently only two are used, so why keep more in RAM?) #define Q3RGBGEN_MAXPARMS 3 #define Q3ALPHAGEN_MAXPARMS 1 #define Q3TCGEN_MAXPARMS 6 #define Q3TCMOD_MAXPARMS 6 -#define Q3MAXTCMODS 4 +#define Q3MAXTCMODS 8 #define Q3MAXDEFORMS 4 typedef enum q3wavefunc_e