]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - r_sky.c
fix some crashes related to particles when csqc is not active
[xonotic/darkplaces.git] / r_sky.c
diff --git a/r_sky.c b/r_sky.c
index a50537262d201be997794cdc1273d400e6691d24..401562b8bfaa06d02070a23239ec0c91f38bea88 100644 (file)
--- a/r_sky.c
+++ b/r_sky.c
@@ -56,11 +56,11 @@ void R_SkyStartFrame(void)
        skyrendersphere = false;
        skyrenderbox = false;
        skyrendermasked = false;
-       if (r_sky.integer && !fogenabled)
+       if (r_sky.integer && !r_refdef.fogenabled)
        {
                if (skyboxside[0] || skyboxside[1] || skyboxside[2] || skyboxside[3] || skyboxside[4] || skyboxside[5])
                        skyrenderbox = true;
-               else if (r_refdef.worldmodel->brush.solidskytexture)
+               else if (r_refdef.worldmodel && r_refdef.worldmodel->brush.solidskytexture)
                        skyrendersphere = true;
                // for depth-masked sky, render the sky on the first sky surface encountered
                skyrendernow = true;
@@ -138,11 +138,11 @@ int R_SetSkyBox(const char *sky)
 
        if (strlen(sky) > 1000)
        {
-               Con_Printf("sky name too long (%i, max is 1000)\n", strlen(sky));
+               Con_Printf("sky name too long (%i, max is 1000)\n", (int)strlen(sky));
                return false;
        }
 
-       strcpy(skyname, sky);
+       strlcpy(skyname, sky, sizeof(skyname));
 
        return R_LoadSkyBox();
 }
@@ -268,7 +268,8 @@ int skyboxelements[6*2*3] =
 static void R_SkyBox(void)
 {
        int i;
-       GL_Color(1, 1, 1, 1);
+       // FIXME: fixed function path can't properly handle r_view.colorscale > 1
+       GL_Color(1 * r_view.colorscale, 1 * r_view.colorscale, 1 * r_view.colorscale, 1);
        GL_BlendFunc(GL_ONE, GL_ZERO);
        GL_DepthMask(false);
        GL_DepthTest(false); // don't modify or read zbuffer
@@ -365,7 +366,8 @@ static void R_SkySphere(void)
        speedscale -= (int)speedscale;
        Matrix4x4_CreateTranslate(&scroll2matrix, speedscale, speedscale, 0);
 
-       GL_Color(1, 1, 1, 1);
+       // FIXME: fixed function path can't properly handle r_view.colorscale > 1
+       GL_Color(1 * r_view.colorscale, 1 * r_view.colorscale, 1 * r_view.colorscale, 1);
        GL_BlendFunc(GL_ONE, GL_ZERO);
        GL_DepthMask(true);
        GL_DepthTest(false); // don't modify or read zbuffer
@@ -375,7 +377,7 @@ static void R_SkySphere(void)
        R_Mesh_TexBind(0, R_GetTexture(r_refdef.worldmodel->brush.solidskytexture));
        R_Mesh_TexCoordPointer(0, 2, skysphere_texcoord2f);
        R_Mesh_TexMatrix(0, &scroll1matrix);
-       if (r_textureunits.integer >= 2)
+       if (r_textureunits.integer >= 2 && r_view.colorscale == 1)
        {
                // one pass using GL_DECAL or GL_INTERPOLATE_ARB for alpha layer
                R_Mesh_TexBind(1, R_GetTexture(r_refdef.worldmodel->brush.alphaskytexture));
@@ -406,7 +408,7 @@ void R_Sky(void)
        matrix4x4_t skymatrix;
        if (skyrendermasked)
        {
-               Matrix4x4_CreateTranslate(&skymatrix, r_vieworigin[0], r_vieworigin[1], r_vieworigin[2]);
+               Matrix4x4_CreateTranslate(&skymatrix, r_view.origin[0], r_view.origin[1], r_view.origin[2]);
                R_Mesh_Matrix(&skymatrix);
                if (skyrendersphere)
                {