[Orxonox-commit 7118] r11735 - code/branches/Presentation_HS17_merge/src/modules/asteroidmining

landauf at orxonox.net landauf at orxonox.net
Sun Feb 11 19:19:57 CET 2018


Author: landauf
Date: 2018-02-11 19:19:57 +0100 (Sun, 11 Feb 2018)
New Revision: 11735

Modified:
   code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.cc
   code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidBelt.cc
   code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidField.cc
Log:
[AsteroidMining_HS17] fixed a bunch of memory leaks

Modified: code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.cc
===================================================================
--- code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.cc	2018-02-11 17:06:18 UTC (rev 11734)
+++ code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.cc	2018-02-11 18:19:57 UTC (rev 11735)
@@ -176,7 +176,6 @@
         AsteroidMinable* reborn = new AsteroidMinable(this->context, this->size, this->getPosition(), this->dropStuff);
         reborn->setVelocity(this->getVelocity());
         // reborn->setAngularVelocity(this->getAngularVelocity()); // Add all other stuff, too?
-        (void)reborn; // avoid compiler warning
 
         this->bAlive_ = false;
         this->destroyLater();
@@ -360,19 +359,15 @@
     // Creating the 'chlidren':
     for(int fisch = 0; fisch<num; ++fisch){
 
-        Vector3* pos = new Vector3(0,0,0); // Position offset
+        Vector3 pos = Vector3::ZERO; // Position offset
         if(num > 1){// not required if there-s just one child
             float r = masses[fisch]/rScaling;
-            pos = new Vector3(r*sin(theta[fisch])*cos(phi[fisch]), r*sin(theta[fisch])*sin(phi[fisch]), r*cos(theta[fisch])); // convert spheric coordinates to vector
+            pos = Vector3(r*sin(theta[fisch])*cos(phi[fisch]), r*sin(theta[fisch])*sin(phi[fisch]), r*cos(theta[fisch])); // convert spheric coordinates to vector
         }
         
-        AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + *pos, this->dropStuff);
+        AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + pos, this->dropStuff);
         child->setVelocity(this->getVelocity());
 
-        if(child == nullptr){
-            orxout(internal_error, context::pickups) << "Weird, can't create new AsteroidMinable." << endl;
-        }
-
     }
     // orxout() << "Leaving spawnChildren() method. " << endl;
 }

Modified: code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidBelt.cc
===================================================================
--- code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidBelt.cc	2018-02-11 17:06:18 UTC (rev 11734)
+++ code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidBelt.cc	2018-02-11 18:19:57 UTC (rev 11735)
@@ -79,6 +79,7 @@
         this->radius1 = 7800;
 
         this->mDensity = 0.3;
+        this->foggy = true;
         this->fogDensity = 0.5;
 
         this->tiltAt = 0.0; 
@@ -112,8 +113,8 @@
                 globi = globi + dTheta; 
             }
             
-            Vector3* pos = new Vector3(radius*cos(sepp)*sin(globi), radius*sin(sepp)*sin(globi), radius*cos(globi)); 
-            new SpicedAsteroidField(this->context, this->position + *pos, this->minSize, this->maxSize, width, segmentCount, this->foggy, this->mDensity, this->fogDensity);
+            Vector3 pos(radius*cos(sepp)*sin(globi), radius*sin(sepp)*sin(globi), radius*cos(globi));
+            new SpicedAsteroidField(this->context, this->position + pos, this->minSize, this->maxSize, width, segmentCount, this->foggy, this->mDensity, this->fogDensity);
             
         }
         

Modified: code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidField.cc
===================================================================
--- code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidField.cc	2018-02-11 17:06:18 UTC (rev 11734)
+++ code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidField.cc	2018-02-11 18:19:57 UTC (rev 11735)
@@ -106,8 +106,6 @@
         int pY;
         int pZ;
 
-        Vector3* relPos; 
-
         for(int gertrud = 0; gertrud<count; ++gertrud){
 
             AsteroidMinable* a = new AsteroidMinable(this->context);
@@ -118,8 +116,8 @@
             pX = round(rnd()*2*this->radius) - radius;
             pY = round(rnd()*2*this->radius) - radius;
             pZ = round(rnd()*2*this->radius) - radius;
-            relPos = new Vector3(pX, pY, pZ);
-            a->setPosition(this->position + *relPos);
+            Vector3 relPos(pX, pY, pZ);
+            a->setPosition(this->position + relPos);
 
             bool spiced = (rnd() < (this->mDensity)); // Whether the asteroid does drop pickups etc. 
             a->toggleDropStuff(spiced);
@@ -127,10 +125,9 @@
             a->setVelocity(this->getVelocity()); 
             
             // Fog is iplemented with billboards (as in asteroidField.lua, that bloke had the idea)
-            Billboard* bb;
             if(this->foggy && mod(gertrud, 5) == 0){
-                bb = new Billboard(this->context);
-                bb->setPosition(this->position + *relPos);
+                Billboard* bb = new Billboard(this->context);
+                bb->setPosition(this->position + relPos);
                 bb->setMaterial("Smoke/Smoke");
                 bb->setScale(size);
                 bb->setColour(ColourValue(this->fogDensity, this->fogDensity, this->fogDensity));    



More information about the Orxonox-commit mailing list