[fusion-commits] Animation plugin: Changes to 'master' (b5a42907fbb1040f288231c71e09823e8c2d4447)
cornelius at server.opencompositing.org
cornelius at server.opencompositing.org
Fri May 9 22:06:13 CEST 2008
New commits:
commit b5a42907fbb1040f288231c71e09823e8c2d4447
Author: Erkin Bahceci <erkinbah at gmail.com>
Date: Fri May 9 23:00:44 2008 +0300
Fix crash during magic lamp animation (bug 932).
animation-internal.h | 4 ++--
animation.c | 12 ++++--------
magiclamp.c | 50 ++++++++++++++++++++++++++++----------------------
3 files changed, 34 insertions(+), 32 deletions(-)
Modified: fusion/plugins/animation/animation-internal.h
===================================================================
--- fusion/plugins/animation/animation-internal.h
+++ fusion/plugins/animation/animation-internal.h
@@ -234,8 +234,6 @@ typedef struct _Model
Vector scale;
Point scaleOrigin;
- int magicLampWaveCount;
- WaveParam *magicLampWaves;
WindowEvent forWindowEvent;
float topHeight;
float bottomHeight;
@@ -628,6 +626,8 @@ typedef struct _AnimWindow
// for magic lamp
Bool minimizeToTop;
+ int magicLampWaveCount;
+ WaveParam *magicLampWaves;
// for glide effect
float glideModRotAngle; // The angle of rotation modulo 360
Modified: fusion/plugins/animation/animation.c
===================================================================
--- fusion/plugins/animation/animation.c
+++ fusion/plugins/animation/animation.c
@@ -1267,8 +1267,6 @@ static Model *createModel(CompWindow * w,
"Not enough memory");
return 0;
}
- model->magicLampWaveCount = 0;
- model->magicLampWaves = NULL;
model->gridWidth = gridWidth;
model->gridHeight = gridHeight;
@@ -1308,8 +1306,6 @@ animFreeModel(AnimWindow *aw)
if (!aw->model)
return;
- if (aw->model->magicLampWaves)
- free(aw->model->magicLampWaves);
if (aw->model->objects)
free(aw->model->objects);
free(aw->model);
@@ -1433,11 +1429,11 @@ static void postAnimationCleanupCustom (CompWindow * w,
aw->curAnimEffect = AnimEffectNone;
aw->animOverrideProgressDir = 0;
- if (aw->model)
+ aw->magicLampWaveCount = 0;
+ if (aw->magicLampWaves)
{
- if (aw->model->magicLampWaves)
- free(aw->model->magicLampWaves);
- aw->model->magicLampWaves = 0;
+ free(aw->magicLampWaves);
+ aw->magicLampWaves = 0;
}
}
Modified: fusion/plugins/animation/magiclamp.c
===================================================================
--- fusion/plugins/animation/magiclamp.c
+++ fusion/plugins/animation/magiclamp.c
@@ -56,8 +56,6 @@ void fxMagicLampInit(CompScreen * s, CompWindow * w)
ANIM_SCREEN(s);
ANIM_WINDOW(w);
- Model *model = aw->model;
-
int screenHeight = s->height;
aw->minimizeToTop = (WIN_Y(w) + WIN_H(w) / 2) >
(aw->icon.y + aw->icon.height / 2);
@@ -84,7 +82,7 @@ void fxMagicLampInit(CompScreen * s, CompWindow * w)
if (maxWaves == 0)
{
- model->magicLampWaveCount = 0;
+ aw->magicLampWaveCount = 0;
return;
}
@@ -95,13 +93,20 @@ void fxMagicLampInit(CompScreen * s, CompWindow * w)
else
distance = aw->icon.y - WIN_Y(w);
- model->magicLampWaveCount =
+ aw->magicLampWaveCount =
1 + (float)maxWaves *distance / screenHeight;
- if (!(model->magicLampWaves))
- model->magicLampWaves =
- calloc(model->magicLampWaveCount, sizeof(WaveParam));
-
+ if (!(aw->magicLampWaves))
+ {
+ aw->magicLampWaves =
+ calloc(aw->magicLampWaveCount, sizeof(WaveParam));
+ if (!aw->magicLampWaves)
+ {
+ compLogMessage (w->screen->display, "animation", CompLogLevelError,
+ "Not enough memory");
+ return;
+ }
+ }
// Compute wave parameters
int ampDirection = (RAND_FLOAT() < 0.5 ? 1 : -1);
@@ -109,28 +114,27 @@ void fxMagicLampInit(CompScreen * s, CompWindow * w)
float minHalfWidth = 0.22f;
float maxHalfWidth = 0.38f;
- for (i = 0; i < model->magicLampWaveCount; i++)
+ for (i = 0; i < aw->magicLampWaveCount; i++)
{
- model->magicLampWaves[i].amp =
+ aw->magicLampWaves[i].amp =
ampDirection * (waveAmpMax - waveAmpMin) *
rand() / RAND_MAX + ampDirection * waveAmpMin;
- model->magicLampWaves[i].halfWidth =
+ aw->magicLampWaves[i].halfWidth =
RAND_FLOAT() * (maxHalfWidth -
minHalfWidth) + minHalfWidth;
// avoid offset at top and bottom part by added waves
- float availPos = 1 - 2 * model->magicLampWaves[i].halfWidth;
+ float availPos = 1 - 2 * aw->magicLampWaves[i].halfWidth;
float posInAvailSegment = 0;
if (i > 0)
posInAvailSegment =
- (availPos /
- model->magicLampWaveCount) * rand() / RAND_MAX;
+ (availPos / aw->magicLampWaveCount) * rand() / RAND_MAX;
- model->magicLampWaves[i].pos =
+ aw->magicLampWaves[i].pos =
(posInAvailSegment +
- i * availPos / model->magicLampWaveCount +
- model->magicLampWaves[i].halfWidth);
+ i * availPos / aw->magicLampWaveCount +
+ aw->magicLampWaves[i].halfWidth);
// switch wave direction
ampDirection *= -1;
@@ -246,15 +250,14 @@ fxMagicLampModelStepObject(CompWindow * w,
// Apply waves
int i;
- for (i = 0; i < model->magicLampWaveCount; i++)
+ for (i = 0; i < aw->magicLampWaveCount; i++)
{
- float cosfx =
- (fx - model->magicLampWaves[i].pos) /
- model->magicLampWaves[i].halfWidth;
+ float cosfx = ((fx - aw->magicLampWaves[i].pos) /
+ aw->magicLampWaves[i].halfWidth);
if (cosfx < -1 || cosfx > 1)
continue;
targetx +=
- model->magicLampWaves[i].amp * model->scale.x *
+ aw->magicLampWaves[i].amp * model->scale.x *
(cos(cosfx * M_PI) + 1) / 2;
}
@@ -306,6 +309,9 @@ fxMagicLampModelStep (CompScreen *s, CompWindow *w, float time)
}
float forwardProgress = defaultAnimProgress(aw);
+ if (aw->magicLampWaveCount > 0 && !aw->magicLampWaves)
+ return;
+
int i;
for (i = 0; i < model->numObjects; i++)
fxMagicLampModelStepObject(w, model, &model->objects[i],
More information about the commits
mailing list