Index: trunk/src/lib/particles/particle_emitter.cc
===================================================================
--- trunk/src/lib/particles/particle_emitter.cc	(revision 6623)
+++ trunk/src/lib/particles/particle_emitter.cc	(revision 6625)
@@ -124,5 +124,4 @@
   else if (this->system != NULL)
     this->system->removeEmitter(this);
-  this->system = system;
 }
 
Index: trunk/src/lib/particles/particle_system.cc
===================================================================
--- trunk/src/lib/particles/particle_system.cc	(revision 6623)
+++ trunk/src/lib/particles/particle_system.cc	(revision 6625)
@@ -51,24 +51,24 @@
 ParticleSystem::~ParticleSystem()
 {
-   // deleting all the living Particles
-   while (this->particles)
-     {
-       Particle* tmpDelPart = this->particles;
-       this->particles = this->particles->next;
-       delete tmpDelPart;
-     }
-
-   // deleting all the dead particles
-   while (this->deadList)
-     {
-       Particle* tmpDelPart = this->deadList;
-       this->deadList = this->deadList->next;
-       delete tmpDelPart;
-     }
-
-     while(!this->emitters.empty())
-     {
-       this->removeEmitter(this->emitters.front());
-     }
+  // deleting all the living Particles
+  while (this->particles)
+  {
+    Particle* tmpDelPart = this->particles;
+    this->particles = this->particles->next;
+    delete tmpDelPart;
+  }
+
+  // deleting all the dead particles
+  while (this->deadList)
+  {
+    Particle* tmpDelPart = this->deadList;
+    this->deadList = this->deadList->next;
+    delete tmpDelPart;
+  }
+
+  while(!this->emitters.empty())
+  {
+    this->removeEmitter(this->emitters.front());
+  }
 
 }
@@ -102,11 +102,11 @@
 
   LoadParam(root, "max-count", this, ParticleSystem, setMaxCount)
-      .describe("the maximal count of Particles, that can be emitted into this system");
+  .describe("the maximal count of Particles, that can be emitted into this system");
 
   LoadParam(root, "life-span", this, ParticleSystem, setLifeSpan)
-      .describe("sets the life-span of the Particles.");
+  .describe("sets the life-span of the Particles.");
 
   LoadParam(root, "conserve", this, ParticleSystem, setConserve)
-      .describe("sets the Conserve factor of the Particles (1.0: they keep all their energy, 0.0:they keep no energy)");
+  .describe("sets the Conserve factor of the Particles (1.0: they keep all their energy, 0.0:they keep no energy)");
 
   LoadParamXML(root, "emitters", this, ParticleSystem, loadEmitters);
@@ -115,13 +115,13 @@
   {
     element->ToText();
-  // PER-PARTICLE-ATTRIBUTES:
+    // PER-PARTICLE-ATTRIBUTES:
     LoadParam_CYCLE(element, "radius", this, ParticleSystem, setRadius)
-        .describe("The Radius of each particle over time (TimeIndex [0-1], radius at TimeIndex, randomRadius at TimeIndex)");
+    .describe("The Radius of each particle over time (TimeIndex [0-1], radius at TimeIndex, randomRadius at TimeIndex)");
 
     LoadParam_CYCLE(element, "mass", this, ParticleSystem, setMass)
-        .describe("The Mass of each particle over time (TimeIndex: [0-1], mass at TimeIndex, randomMass at TimeIndex)");
+    .describe("The Mass of each particle over time (TimeIndex: [0-1], mass at TimeIndex, randomMass at TimeIndex)");
 
     LoadParam_CYCLE(element, "color", this, ParticleSystem, setColor)
-        .describe("The Color of each particle over time (TimeIndex: [0-1], red: [0-1], green: [0-1], blue: [0-1], alpha: [0-1])");
+    .describe("The Color of each particle over time (TimeIndex: [0-1], red: [0-1], green: [0-1], blue: [0-1], alpha: [0-1])");
   }
   LOAD_PARAM_END_CYCLE(element);
@@ -229,4 +229,5 @@
   if (emitter->getSystem() != NULL)
     emitter->getSystem()->removeEmitter(emitter);
+  emitter->system = this;
   this->emitters.push_back(emitter);
 }
@@ -235,7 +236,10 @@
 void ParticleSystem::removeEmitter(ParticleEmitter* emitter)
 {
-  std::list<ParticleEmitter*>::iterator it = std::find(this->emitters.begin(), this->emitters.end(), emitter);
+  assert (emitter != NULL);
+  emitter->system = NULL;
+  this->emitters.remove(emitter);
+  /*  std::list<ParticleEmitter*>::iterator it = std::find(this->emitters.begin(), this->emitters.end(), emitter);
   if (it != this->emitters.end())
-    this->emitters.erase(it);
+    this->emitters.erase(it);*/
 }
 
@@ -251,64 +255,64 @@
   Particle* prevPart = NULL;
   while (likely(tickPart != NULL))
+  {
+    // applying force to the System.
+    if (likely (tickPart->mass > 0.0))
+      tickPart->velocity += tickPart->extForce / tickPart->mass * dt;
+    // rendering new position.
+    tickPart->position += tickPart->velocity * dt;
+    tickPart->orientation += tickPart->momentum *dt;
+
+    tickPart->radius = radiusAnim.getValue(tickPart->lifeCycle)
+                       + randRadiusAnim.getValue(tickPart->lifeCycle) * tickPart->radiusRand;
+
+    tickPart->mass = massAnim.getValue(tickPart->lifeCycle)
+                     + randMassAnim.getValue(tickPart->lifeCycle) * tickPart->massRand;
+
+    tickPart->extForce = Vector(0,0,0);
+
+    // applying Color
+    tickPart->color[0] = this->colorAnim[0].getValue(tickPart->lifeCycle);
+    tickPart->color[1] = this->colorAnim[1].getValue(tickPart->lifeCycle);
+    tickPart->color[2] = this->colorAnim[2].getValue(tickPart->lifeCycle);
+    tickPart->color[3] = this->colorAnim[3].getValue(tickPart->lifeCycle);
+
+    // many more to come
+
+    if (this->conserve < 1.0)
     {
-      // applying force to the System.
-      if (likely (tickPart->mass > 0.0))
-        tickPart->velocity += tickPart->extForce / tickPart->mass * dt;
-      // rendering new position.
-      tickPart->position += tickPart->velocity * dt;
-      tickPart->orientation += tickPart->momentum *dt;
-
-      tickPart->radius = radiusAnim.getValue(tickPart->lifeCycle)
-        + randRadiusAnim.getValue(tickPart->lifeCycle) * tickPart->radiusRand;
-
-      tickPart->mass = massAnim.getValue(tickPart->lifeCycle)
-        + randMassAnim.getValue(tickPart->lifeCycle) * tickPart->massRand;
-
-      tickPart->extForce = Vector(0,0,0);
-
-      // applying Color
-      tickPart->color[0] = this->colorAnim[0].getValue(tickPart->lifeCycle);
-      tickPart->color[1] = this->colorAnim[1].getValue(tickPart->lifeCycle);
-      tickPart->color[2] = this->colorAnim[2].getValue(tickPart->lifeCycle);
-      tickPart->color[3] = this->colorAnim[3].getValue(tickPart->lifeCycle);
-
-      // many more to come
-
-      if (this->conserve < 1.0)
+      tickPart->velocity *= this->conserve;
+      tickPart->momentum *= this->conserve;
+    }
+    // find out if we have to delete tickPart
+    if (unlikely((tickPart->lifeCycle += dt/tickPart->lifeTime) >= 1.0))
+    {
+      // remove the particle from the list
+      if (likely(prevPart != NULL))
       {
-        tickPart->velocity *= this->conserve;
-        tickPart->momentum *= this->conserve;
+        prevPart->next = tickPart->next;
+        tickPart->next = this->deadList;
+        this->deadList = tickPart;
+        tickPart = prevPart->next;
       }
-      // find out if we have to delete tickPart
-      if (unlikely((tickPart->lifeCycle += dt/tickPart->lifeTime) >= 1.0))
-        {
-          // remove the particle from the list
-          if (likely(prevPart != NULL))
-            {
-              prevPart->next = tickPart->next;
-              tickPart->next = this->deadList;
-              this->deadList = tickPart;
-              tickPart = prevPart->next;
-            }
-          else
-            {
-              prevPart = NULL;
-              this->particles = tickPart->next;
-              tickPart->next = this->deadList;
-              this->deadList = tickPart;
-              tickPart = this->particles;
-            }
-          --this->count;
-        }
       else
-        {
-          prevPart = tickPart;
-          tickPart = tickPart->next;
-        }
+      {
+        prevPart = NULL;
+        this->particles = tickPart->next;
+        tickPart->next = this->deadList;
+        this->deadList = tickPart;
+        tickPart = this->particles;
+      }
+      --this->count;
     }
-
-    std::list<ParticleEmitter*>::iterator emitter;
-    for (emitter = this->emitters.begin(); emitter != this->emitters.end(); emitter++)
-      (*emitter)->tick(dt);
+    else
+    {
+      prevPart = tickPart;
+      tickPart = tickPart->next;
+    }
+  }
+
+  std::list<ParticleEmitter*>::iterator emitter;
+  for (emitter = this->emitters.begin(); emitter != this->emitters.end(); emitter++)
+    (*emitter)->tick(dt);
 }
 
@@ -321,8 +325,8 @@
   Particle* tickPart = particles;
   while (tickPart)
-    {
-      tickPart->extForce += field->calcForce(tickPart->position);
-      tickPart = tickPart->next;
-    }
+  {
+    tickPart->extForce += field->calcForce(tickPart->position);
+    tickPart = tickPart->next;
+  }
 }
 
@@ -427,53 +431,53 @@
 {
   if (this->count <= this->maxCount)
+  {
+    // if it is the first Particle
+    if (unlikely(particles == NULL))
     {
-      // if it is the first Particle
-      if (unlikely(particles == NULL))
-        {
-          if (likely(deadList != NULL))
-            {
-              this->particles = this->deadList;
-              deadList = deadList->next;
-            }
-          else
-            {
-              PRINTF(5)("Generating new Particle\n");
-              this->particles = new Particle;
-            }
-          this->particles->next = NULL;
-        }
-      // filling the List from the beginning
+      if (likely(deadList != NULL))
+      {
+        this->particles = this->deadList;
+        deadList = deadList->next;
+      }
       else
-        {
-          Particle* tmpPart;
-          if (likely(deadList != NULL))
-            {
-              tmpPart = this->deadList;
-              deadList = deadList->next;
-            }
-          else
-            {
-              PRINTF(5)("Generating new Particle\n");
-              tmpPart = new Particle;
-            }
-          tmpPart->next = this->particles;
-          this->particles = tmpPart;
-        }
-      particles->lifeTime = this->lifeSpan + (float)(rand()/RAND_MAX)* this->randomLifeSpan;
-      particles->lifeCycle = 0.0;
-      particles->position = position;
-      particles->velocity = velocity;
-
-      particles->orientation = orientation;
-      particles->momentum = momentum;
-
-      //  particle->rotation = ; //! @todo rotation is once again something to be done.
-      particles->massRand = 2*(float)rand()/RAND_MAX -1;
-      particles->radiusRand = 2* (float)rand()/RAND_MAX -1;
-      particles->mass = this->massAnim.getValue(0.0) + this->randMassAnim.getValue(0.0)*particles->massRand;
-      particles->radius = this->radiusAnim.getValue(0.0) + this->randRadiusAnim.getValue(0.0)*particles->radiusRand;
-
-      ++this->count;
+      {
+        PRINTF(5)("Generating new Particle\n");
+        this->particles = new Particle;
+      }
+      this->particles->next = NULL;
     }
+    // filling the List from the beginning
+    else
+    {
+      Particle* tmpPart;
+      if (likely(deadList != NULL))
+      {
+        tmpPart = this->deadList;
+        deadList = deadList->next;
+      }
+      else
+      {
+        PRINTF(5)("Generating new Particle\n");
+        tmpPart = new Particle;
+      }
+      tmpPart->next = this->particles;
+      this->particles = tmpPart;
+    }
+    particles->lifeTime = this->lifeSpan + (float)(rand()/RAND_MAX)* this->randomLifeSpan;
+    particles->lifeCycle = 0.0;
+    particles->position = position;
+    particles->velocity = velocity;
+
+    particles->orientation = orientation;
+    particles->momentum = momentum;
+
+    //  particle->rotation = ; //! @todo rotation is once again something to be done.
+    particles->massRand = 2*(float)rand()/RAND_MAX -1;
+    particles->radiusRand = 2* (float)rand()/RAND_MAX -1;
+    particles->mass = this->massAnim.getValue(0.0) + this->randMassAnim.getValue(0.0)*particles->massRand;
+    particles->radius = this->radiusAnim.getValue(0.0) + this->randRadiusAnim.getValue(0.0)*particles->radiusRand;
+
+    ++this->count;
+  }
   else
     PRINTF(5)("maximum count of particles reached not adding any more\n");
@@ -487,10 +491,10 @@
   PRINT(0)("  ParticleCount: %d, maximumCount: %d :: filled %d%%\n", this->count, this->maxCount, 100*this->count/this->maxCount);
   if (deadList)
-    {
-      PRINT(0)("  - ParticleDeadList is used: ");
-      int i = 1;
-      Particle* tmpPart = this->deadList;
-      while (tmpPart = tmpPart->next) ++i;
-      PRINT(0)("count: %d\n", i);
-    }
-}
+  {
+    PRINT(0)("  - ParticleDeadList is used: ");
+    int i = 1;
+    Particle* tmpPart = this->deadList;
+    while (tmpPart = tmpPart->next) ++i;
+    PRINT(0)("count: %d\n", i);
+  }
+}
