Index: code/branches/shaders_merge/src/orxonox/Scene.cc
===================================================================
--- code/branches/shaders_merge/src/orxonox/Scene.cc	(revision 11075)
+++ code/branches/shaders_merge/src/orxonox/Scene.cc	(revision 11078)
@@ -98,4 +98,5 @@
             this->rootSceneNode_ = this->sceneManager_->getRootSceneNode();
 
+            this->renderQueueListener_ = nullptr;
             this->radar_ = nullptr;
         }
@@ -125,5 +126,9 @@
 
             if (GameMode::showsGraphics())
+            {
+                this->sceneManager_->removeRenderQueueListener(this->renderQueueListener_);
+                delete this->renderQueueListener_;
                 Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_);
+            }
             else
                 delete this->sceneManager_;
Index: code/branches/shaders_merge/src/orxonox/graphics/LensFlare.cc
===================================================================
--- code/branches/shaders_merge/src/orxonox/graphics/LensFlare.cc	(revision 11075)
+++ code/branches/shaders_merge/src/orxonox/graphics/LensFlare.cc	(revision 11078)
@@ -46,18 +46,17 @@
     RegisterClass(LensFlare);
     
-    LensFlare::LensFlare(Context* context) : StaticEntity(context), scale_(1.0f), fadeOnViewBorder_(true), fadeResolution_(7), fadeExponent_(2.0f), colour_(new ColourValue(1.0f,0.9f,0.9f))
+    LensFlare::LensFlare(Context* context) : StaticEntity(context), scale_(1.0f), fadeOnViewBorder_(true), fadeResolution_(7), fadeExponent_(2.0f)
     {
         RegisterObject(LensFlare);
         
-        this->lensConfiguration_=new std::vector<LensFlare::Lens*>();
-        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/burst"),1.0f,1.0f,1.0f)); //main burst
-        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/burst"),0.7f,1.2f,1.05f)); //secondary burst
-        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/bursthalo"),0.7f,0.9f,1.0f)); //halo around main burst
-        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/ring"),0.1f,2.5f,0.9f)); //all the different distanced lenses
-        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/iris"),0.1f,0.2f,0.5f));
-        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo5"),0.1f,0.3f,0.45f));
-        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo5"),0.4f,0.2f,0.35f));
-        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/iris"),0.1f,0.4f,0.25f));
-        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo4"),0.05f,0.2f,0.2f));
+        this->lensConfiguration_.emplace_back("lensflare/burst",     1.0f,  1.0f, 1.0f); //main burst
+        this->lensConfiguration_.emplace_back("lensflare/burst",     0.7f,  1.2f, 1.05f); //secondary burst
+        this->lensConfiguration_.emplace_back("lensflare/bursthalo", 0.7f,  0.9f, 1.0f); //halo around main burst
+        this->lensConfiguration_.emplace_back("lensflare/ring",      0.1f,  2.5f, 0.9f); //all the different distanced lenses
+        this->lensConfiguration_.emplace_back("lensflare/iris",      0.1f,  0.2f, 0.5f);
+        this->lensConfiguration_.emplace_back("lensflare/halo5",     0.1f,  0.3f, 0.45f);
+        this->lensConfiguration_.emplace_back("lensflare/halo5",     0.4f,  0.2f, 0.35f);
+        this->lensConfiguration_.emplace_back("lensflare/iris",      0.1f,  0.4f, 0.25f);
+        this->lensConfiguration_.emplace_back("lensflare/halo4",     0.05f, 0.2f, 0.2f);
         
         this->createBillboards();
@@ -100,7 +99,8 @@
         this->attach(this->occlusionBillboard_);
         
-        for(std::vector<LensFlare::Lens*>::iterator it = lensConfiguration_->begin(); it != lensConfiguration_->end(); ++it) {
-            Billboard* lensPart=new Billboard(this->getContext());
-            lensPart->setMaterial(*(*it)->material_);
+        for (const LensFlare::Lens& lens : lensConfiguration_)
+        {
+            Billboard* lensPart = new Billboard(this->getContext());
+            lensPart->setMaterial(lens.material_);
             lensPart->disableFrustumCulling();
             lensPart->setVisible(true);
@@ -119,16 +119,19 @@
         is the (point-)light source currently visible
     */
-    void LensFlare::updateBillboardStates(Vector3& viewDirection, float dimension, bool lightIsVisible)
+    void LensFlare::updateBillboardStates(const Vector3& viewDirection, float dimension, bool lightIsVisible)
     { 
-        this->occlusionBillboard_->setDefaultDimensions(dimension*0.5f,dimension*0.5f);
+        this->occlusionBillboard_->setDefaultDimensions(dimension * 0.5f, dimension * 0.5f);
         this->occlusionBillboard_->setVisible(lightIsVisible);
-        std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin();
-        it++;
-        for(int i=0; it != this->getAttachedObjects().end(); it++) {
-            Billboard* billboard=static_cast<Billboard*>(*it);
-            LensFlare::Lens* lens=lensConfiguration_->at(i);
-            billboard->setPosition(-viewDirection*(1.0f-lens->position_));
+
+        int i = 0;
+        for (WorldEntity* attachedObject : this->getAttachedObjects())
+        {
+            Billboard* billboard = orxonox_cast<Billboard*>(attachedObject);
+            if (billboard == this->occlusionBillboard_)
+                continue;
+            const LensFlare::Lens& lens = lensConfiguration_.at(i);
+            billboard->setPosition(-viewDirection * (1.0f - lens.position_));
             billboard->setVisible(lightIsVisible);
-            billboard->setDefaultDimensions(dimension*lens->scale_,dimension*lens->scale_);
+            billboard->setDefaultDimensions(dimension * lens.scale_, dimension * lens.scale_);
             i++;
         }
@@ -143,13 +146,14 @@
     void LensFlare::updateBillboardAlphas(float alpha)
     {
-        this->colour_->a=alpha;
-        std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin();
-        it++;
-        for(int i=0;it!=this->getAttachedObjects().end(); it++) {
-            ColourValue* cur=new ColourValue(0,0,0,0);
-            (*cur)+= *(this->colour_);
-            cur->a*=lensConfiguration_->at(i)->alpha_;
-            Billboard* billboard=static_cast<Billboard*>(*it);
-            billboard->setColour(*cur);
+        ColourValue cur = this->colour_;
+
+        int i = 0;
+        for (WorldEntity* attachedObject : this->getAttachedObjects())
+        {
+            Billboard* billboard = orxonox_cast<Billboard*>(attachedObject);
+            if (billboard == this->occlusionBillboard_)
+                continue;
+            cur.a = alpha * lensConfiguration_.at(i).alpha_;
+            billboard->setColour(cur);
             i++;
         }
@@ -166,17 +170,17 @@
     unsigned int LensFlare::getPointCount(float dimension) const
     {
-        Ogre::Camera* camera=CameraManager::getInstance().getActiveCamera()->getOgreCamera();
+        Ogre::Camera* camera = CameraManager::getInstance().getActiveCamera()->getOgreCamera();
         Vector3 position = this->getWorldPosition();
         Vector3 nX = camera->getDerivedOrientation().xAxis().normalisedCopy();
         Vector3 nY = camera->getDerivedOrientation().yAxis().normalisedCopy();
-        int halfRes=fadeResolution_/2;
-        float resDim=dimension/fadeResolution_;
-        unsigned int count=0;
-        for(int i=-halfRes;i<=halfRes;i++)
-        {
-            for(int j=-halfRes;j<=halfRes;j++)
+        int halfRes = fadeResolution_ / 2;
+        float resDim = dimension / fadeResolution_;
+        unsigned int count = 0;
+        for (int i = -halfRes; i <= halfRes; i++)
+        {
+            for (int j = -halfRes; j <= halfRes; j++)
             {
-                Vector3 point=position+(i*resDim)*nX+(j*resDim)*nY;//generate point samples
-                if(camera->isVisible(point))
+                Vector3 point = position + (i*resDim) * nX + (j*resDim) * nY;//generate point samples
+                if (camera->isVisible(point))
                 {
                     count++;
@@ -191,31 +195,32 @@
         if(this->isVisible())
         {
-            Ogre::Camera* camera=CameraManager::getInstance().getActiveCamera()->getOgreCamera(); //get active Ogre Camera Instance, so we can check whether the light source is visible
-            this->cameraDistance_=camera->getDerivedPosition().distance(this->getPosition());
-            float dimension=this->cameraDistance_*this->scale_;
-            if(!this->fadeOnViewBorder_)
+            // get the current distance of the lensflare center from the camera
+            Ogre::Camera* camera = CameraManager::getInstance().getActiveCamera()->getOgreCamera(); //get active Ogre Camera Instance, so we can check whether the light source is visible
+            float cameraDistance = camera->getDerivedPosition().distance(this->getPosition());
+            float dimension = cameraDistance * this->scale_;
+            if (!this->fadeOnViewBorder_)
             {
-                this->fadeResolution_=3;//this is so we can still determine when the billboard has left the screen
+                this->fadeResolution_ = 3;//this is so we can still determine when the billboard has left the screen
             }
-            unsigned int pointCount=this->getPointCount(dimension*0.25f*this->scale_);
-            Vector3 viewDirection=this->getWorldPosition()-camera->getDerivedPosition()-camera->getDerivedDirection()*this->cameraDistance_;
-            updateBillboardStates(viewDirection,dimension,pointCount>0);
-            if(pointCount>0) {
-                Ogre::Sphere* sphere=new Ogre::Sphere(this->getPosition(),dimension*0.25f*this->scale_);
+            unsigned int pointCount = this->getPointCount(dimension * 0.25f * this->scale_);
+            Vector3 viewDirection = this->getWorldPosition() - camera->getDerivedPosition() - camera->getDerivedDirection() * cameraDistance;
+            this->updateBillboardStates(viewDirection, dimension, pointCount > 0);
+            if (pointCount > 0)
+            {
+                Ogre::Sphere sphere(this->getPosition(), dimension * 0.25f * this->scale_);
                 float left, right, top, bottom;
-                camera->projectSphere(*sphere,&left,&top,&right,&bottom);//approximate maximum pixel count of billboard with a sphere
-                delete sphere;
+                camera->projectSphere(sphere, &left, &top, &right, &bottom);//approximate maximum pixel count of billboard with a sphere
                 
                 Ogre::RenderWindow* window = GraphicsManager::getInstance().getRenderWindow();
-                float maxCount=(right-left)*(top-bottom)*window->getWidth()*window->getHeight()*0.25f;
-                float pixelCount=this->getScene()->getRenderQueueListener()->getPixelCount();//get pixel count
-                float ratio=(maxCount<0.0f)?0.0f:(pixelCount/maxCount);//prevent underflow and division by zero
-                float borderRatio=1.0f;
-                if(this->fadeOnViewBorder_)
+                float maxCount = (right - left) * (top - bottom) * window->getWidth() * window->getHeight() * 0.25f;
+                unsigned int pixelCount = this->getScene()->getRenderQueueListener()->getPixelCount();//get pixel count
+                float ratio = (maxCount < 0.0f) ? 0.0f : (1.0f * pixelCount / maxCount);//prevent underflow and division by zero
+                float borderRatio = 1.0f;
+                if (this->fadeOnViewBorder_)
                 {
-                    borderRatio=((float) pointCount)/(((float) fadeResolution_)*((float) fadeResolution_));//ratio for the border fade
+                    borderRatio = ((float) pointCount) / (((float) fadeResolution_) * ((float) fadeResolution_));//ratio for the border fade
                 }
                 //update alpha values of all billboards except the HOQ billboard
-                this->updateBillboardAlphas(std::min(1.0f,std::pow(std::min(ratio,borderRatio),this->fadeExponent_)));
+                this->updateBillboardAlphas(std::min(1.0f, std::pow(std::min(ratio, borderRatio), this->fadeExponent_)));
             }
         }
Index: code/branches/shaders_merge/src/orxonox/graphics/LensFlare.h
===================================================================
--- code/branches/shaders_merge/src/orxonox/graphics/LensFlare.h	(revision 11075)
+++ code/branches/shaders_merge/src/orxonox/graphics/LensFlare.h	(revision 11078)
@@ -67,14 +67,14 @@
           {
               public:
-                  std::string* material_;//!< Which material should the Lens use, current choices include burst, bursthalo, halo1, halo2, halo3
+                  std::string material_;//!< Which material should the Lens use, current choices include burst, bursthalo, halo1, halo2, halo3
                   float alpha_;//!< Which base alpha value should the Lens use
                   float scale_;//!< Which base scale should the Lens Flare have
                   float position_;//!< This defines how far along the view direction the flare should be positioned, e.g. 0.5 would position the flare halfway between the viewer and the base burst, 0 at the camera, 1 at the burst
-                  Lens(std::string* material, float alpha, float scale, float position)
+                  Lens (const std::string& material, float alpha, float scale, float position)
                   {
-                      this->material_=material;
-                      this->alpha_=alpha;
-                      this->scale_=scale;
-                      this->position_=position;
+                      this->material_ = material;
+                      this->alpha_ = alpha;
+                      this->scale_ = scale;
+                      this->position_ = position;
                   }
           };
@@ -85,5 +85,5 @@
             
             inline void setScale(float scale)
-                { this->scale_=scale; }
+                { this->scale_ = scale; }
             inline float getScale() const
                 { return this->scale_; }
@@ -96,9 +96,5 @@
             */
             inline void setColour(const ColourValue& colour)
-            {
-                this->colour_->r=colour.r;
-                this->colour_->g=colour.g;
-                this->colour_->b=colour.b;
-            }
+                { this->colour_ = colour; }
             /**
             @brief
@@ -107,5 +103,5 @@
             */
             inline const ColourValue& getColour() const
-                { return *(new ColourValue(this->colour_->r,this->colour_->g,this->colour_->b)); }
+                { return this->colour_; }
                 
             /**
@@ -121,5 +117,5 @@
             */
             inline void setFadeResolution(unsigned int fadeResolution)
-                { this->fadeResolution_=fadeResolution>0?fadeResolution:1; }
+                { this->fadeResolution_ = fadeResolution > 0 ? fadeResolution : 1; }
             /**
             @brief
@@ -137,5 +133,5 @@
             */
             inline void setFadeExponent(float exponent)
-                { this->fadeExponent_=exponent; }
+                { this->fadeExponent_ = exponent; }
             /**
             @brief
@@ -153,5 +149,5 @@
             */
             inline void setFadeOnViewBorder(bool fadeOnViewBorder)
-                { this->fadeOnViewBorder_=fadeOnViewBorder; }
+                { this->fadeOnViewBorder_ = fadeOnViewBorder; }
             /**
             @brief
@@ -174,5 +170,5 @@
             void createBillboards();
             
-            void updateBillboardStates(Vector3& viewDirection, float dimension, bool isLightVisible);
+            void updateBillboardStates(const Vector3& viewDirection, float dimension, bool isLightVisible);
             
             void updateBillboardAlphas(float alpha);
@@ -180,12 +176,11 @@
             unsigned int getPointCount(float dimension) const;
             
-            std::vector<Lens*>* lensConfiguration_;//!< this stores the lensConfiguration
+            std::vector<Lens> lensConfiguration_;//!< this stores the lensConfiguration
             Billboard* occlusionBillboard_;//!< this is a transparent billboard used solely for the Hardware Occlusion Query
-            float cameraDistance_;//!< current distance of the lensflare center from the camera
             float scale_;//!< this factor is used to scale the billboard to the desired size
             bool fadeOnViewBorder_;//!< should the effect fade out on the border of the view?
             unsigned int fadeResolution_;//!< how many points should be sampled per axis for the screen border fade. High number => smooth fade, but uses more processing power
             float fadeExponent_;//!< this determines how fast the flare fades away as it gets obstructed
-            ColourValue* colour_;//!< this stores the base colour of the light
+            ColourValue colour_;//!< this stores the base colour of the light
     };
 }
