]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
- fix SEGFAULT when a .shader file has more layers than allowed
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 11 Oct 2007 22:08:05 +0000 (22:08 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 11 Oct 2007 22:08:05 +0000 (22:08 +0000)
- 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

model_shared.c
model_shared.h

index 7266fe6ca1de60391891277cb3837a0c04daff00..880d5f3f8f8483df15c737143288d3f1f53b3a09 100644 (file)
@@ -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;
index c254424ae62dc982e54fac0b1d373c26bfb66791..058073fdd8a10eb55ca9cbc2cb41d1f7dcd3ab4f 100644 (file)
@@ -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