From 24c8663923279e75c59b1bffed6d6ba61f5612b9 Mon Sep 17 00:00:00 2001 From: Rivo Laks Date: Sat, 28 Apr 2007 13:19:36 +0000 Subject: [PATCH] Add GLShader dtor (fixes memory leak). Also fix multiple memory leaks in effects. svn path=/branches/work/kwin_composite/; revision=658761 --- effects/demo_liquid.cpp | 10 ++++++++++ effects/demo_liquid.h | 1 + effects/explosioneffect.cpp | 13 ++++++++++++- effects/explosioneffect.h | 1 + lib/kwinglutils.cpp | 15 +++++++++++++++ lib/kwinglutils.h | 1 + 6 files changed, 40 insertions(+), 1 deletion(-) diff --git a/effects/demo_liquid.cpp b/effects/demo_liquid.cpp index 45f1d6e54d..41c905e153 100644 --- a/effects/demo_liquid.cpp +++ b/effects/demo_liquid.cpp @@ -29,9 +29,19 @@ KWIN_EFFECT_SUPPORTED( Demo_Liquid, LiquidEffect::supported() ); LiquidEffect::LiquidEffect() : Effect() { + mTexture = 0; + mRenderTarget = 0; + mShader = 0; + mTime = 0.0f; mValid = loadData(); } +LiquidEffect::~LiquidEffect() + { + delete mTexture; + delete mRenderTarget; + delete mShader; + } bool LiquidEffect::loadData() { diff --git a/effects/demo_liquid.h b/effects/demo_liquid.h index 2c00e09c8e..228698f350 100644 --- a/effects/demo_liquid.h +++ b/effects/demo_liquid.h @@ -28,6 +28,7 @@ class LiquidEffect : public Effect { public: LiquidEffect(); + ~LiquidEffect(); virtual void prePaintScreen( int* mask, QRegion* region, int time ); virtual void postPaintScreen(); diff --git a/effects/explosioneffect.cpp b/effects/explosioneffect.cpp index 38cd4b1fa3..df4dc6b7df 100644 --- a/effects/explosioneffect.cpp +++ b/effects/explosioneffect.cpp @@ -28,12 +28,23 @@ KWIN_EFFECT_SUPPORTED( Explosion, ExplosionEffect::supported() ); ExplosionEffect::ExplosionEffect() : Effect() { + mShader = 0; + mStartOffsetTex = 0; + mEndOffsetTex = 0; + mActiveAnimations = 0; mValid = true; mInited = false; } - bool ExplosionEffect::supported() +ExplosionEffect::~ExplosionEffect() + { + delete mShader; + delete mStartOffsetTex; + delete mEndOffsetTex; + } + +bool ExplosionEffect::supported() { return GLShader::fragmentShaderSupported() && (effects->compositingType() == OpenGLCompositing); diff --git a/effects/explosioneffect.h b/effects/explosioneffect.h index 64af753fb6..80cc3d4bdf 100644 --- a/effects/explosioneffect.h +++ b/effects/explosioneffect.h @@ -30,6 +30,7 @@ class ExplosionEffect { public: ExplosionEffect(); + ~ExplosionEffect(); virtual void prePaintScreen( int* mask, QRegion* region, int time ); virtual void prePaintWindow( EffectWindow* w, int* mask, QRegion* paint, QRegion* clip, int time ); diff --git a/lib/kwinglutils.cpp b/lib/kwinglutils.cpp index 0b79f4e094..03aa62e704 100644 --- a/lib/kwinglutils.cpp +++ b/lib/kwinglutils.cpp @@ -495,10 +495,25 @@ GLShader::GLShader(const QString& vertexfile, const QString& fragmentfile) { mValid = false; mVariableLocations = 0; + mProgram = 0; loadFromFiles(vertexfile, fragmentfile); } +GLShader::~GLShader() +{ + if(mVariableLocations) + { + mVariableLocations->clear(); + delete mVariableLocations; + } + + if(mProgram) + { + glDeleteProgram(mProgram); + } +} + bool GLShader::loadFromFiles(const QString& vertexfile, const QString& fragmentfile) { QFile vf(vertexfile); diff --git a/lib/kwinglutils.h b/lib/kwinglutils.h index c383606e94..7c6ad5d196 100644 --- a/lib/kwinglutils.h +++ b/lib/kwinglutils.h @@ -132,6 +132,7 @@ class KWIN_EXPORT GLShader { public: GLShader(const QString& vertexfile, const QString& fragmentfile); + ~GLShader(); bool isValid() const { return mValid; } void bind();