summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2007-04-10 20:27:30 +0200
committerDanny Baumann <dannybaumann@web.de>2007-04-10 20:27:30 +0200
commitb66859c33798127bf078fc0c231486097df3f2e3 (patch)
treec34961d659cb870ad80747816276817e154bec95
parent57917c03e1c2e2632989315eb8805d0e0db94f5f (diff)
downloadberyl-premerge-b66859c33798127bf078fc0c231486097df3f2e3.tar.gz
beryl-premerge-b66859c33798127bf078fc0c231486097df3f2e3.tar.bz2
Allocate snowflake array dynamically.
This fixes stack corruption issues as previously the default for the number of snowflakes was larger than the allocated array.
-rw-r--r--src/snow.c40
1 files changed, 34 insertions, 6 deletions
diff --git a/src/snow.c b/src/snow.c
index 7cde777..231cc58 100644
--- a/src/snow.c
+++ b/src/snow.c
@@ -37,8 +37,6 @@
#include <compiz.h>
#include "snow_options.h"
-#define MAX_SNOWFLAKES 1000
-
#define GET_SNOW_DISPLAY(d) \
((SnowDisplay *) (d)->privates[displayPrivateIndex].ptr)
@@ -114,7 +112,7 @@ struct _SnowScreen
Bool displayListNeedsUpdate;
- SnowFlake allSnowFlakes[MAX_SNOWFLAKES];
+ SnowFlake *allSnowFlakes;
};
@@ -153,7 +151,7 @@ static Bool stepSnowPositions(void *sc)
if (!ss->active)
return TRUE;
-
+
int i = 0;
SnowFlake *snowFlake = ss->allSnowFlakes;
int numFlakes = snowGetNumSnowflakes(s->display);
@@ -478,8 +476,9 @@ static void updateSnowTextures(CompScreen * s)
ss->snowTex = realloc(ss->snowTex, sizeof(SnowTexture) * count);
SnowFlake *snowFlake = ss->allSnowFlakes;
+ int numFlakes = snowGetNumSnowflakes(s->display);
- for (i = 0; i < MAX_SNOWFLAKES; i++)
+ for (i = 0; i < numFlakes; i++)
{
setSnowflakeTexture(ss, snowFlake++);
}
@@ -500,9 +499,12 @@ static Bool snowInitScreen(CompPlugin * p, CompScreen * s)
ss->displayListNeedsUpdate = FALSE;
int i = 0;
+ int numFlakes = snowGetNumSnowflakes(s->display);
+
+ ss->allSnowFlakes = malloc(numFlakes * sizeof(SnowFlake));
SnowFlake *snowFlake = ss->allSnowFlakes;
- for (i = 0; i < MAX_SNOWFLAKES; i++)
+ for (i = 0; i < numFlakes; i++)
{
InitiateSnowFlake(ss, snowFlake);
setSnowflakeTexture(ss, snowFlake);
@@ -537,6 +539,9 @@ static void snowFiniScreen(CompPlugin * p, CompScreen * s)
if (ss->snowTexturesLoaded)
free(ss->snowTex);
+ if (ss->allSnowFlakes)
+ free(ss->allSnowFlakes);
+
//Restore the original function
UNWRAP(ss, s, paintScreen);
UNWRAP(ss, s, drawWindow);
@@ -578,6 +583,28 @@ static void snowDisplayOptionChanged(CompDisplay *d, CompOption *opt, SnowDispla
}
}
break;
+ case SnowDisplayOptionNumSnowflakes:
+ {
+ CompScreen *s;
+ int i, numFlakes;
+ SnowFlake *snowFlake;
+
+ numFlakes = snowGetNumSnowflakes(d);
+ for (s = d->screens; s; s = s->next)
+ {
+ SNOW_SCREEN(s);
+ ss->allSnowFlakes = realloc(ss->allSnowFlakes, numFlakes * sizeof(SnowFlake));
+ snowFlake = ss->allSnowFlakes;
+
+ for (i = 0; i < numFlakes; i++)
+ {
+ InitiateSnowFlake(ss, snowFlake);
+ setSnowflakeTexture(ss, snowFlake);
+ snowFlake++;
+ }
+ }
+ }
+ break;
case SnowDisplayOptionSnowTextures:
{
CompScreen *s;
@@ -614,6 +641,7 @@ static Bool snowInitDisplay(CompPlugin * p, CompDisplay * d)
}
snowSetToggleInitiate(d, snowToggle);
+ snowSetNumSnowflakesNotify(d, snowDisplayOptionChanged);
snowSetSnowSizeNotify(d, snowDisplayOptionChanged);
snowSetSnowUpdateDelayNotify(d, snowDisplayOptionChanged);
snowSetSnowTexturesNotify(d, snowDisplayOptionChanged);