Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11190


Ignore:
Timestamp:
May 19, 2016, 5:34:38 PM (8 years ago)
Author:
plehmann
Message:

modified newScriptController to prevent memory leacks caused by tasks

Location:
code/branches/plehmannFS16/src/orxonox/controllers
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.cc

    r11187 r11190  
    130130        }*/
    131131
    132         if(this->taskList_.size() != 0)
    133         {
    134 
    135           orxout() << this->scTime_ << endl;
    136 
    137           if(this->taskList_.front().getStartTime() < this->scTime_)
    138           {
    139              activeTasks_.push_back(this->taskList_.front());
    140              this->taskList_.pop_front();
     132        if(!this->taskList_.empty())
     133        {
     134           orxout() << scTime_ << endl;
     135
     136           orxout() << taskList_.size() << endl;
     137
     138
     139          if(this->taskList_.front()->getStartTime() < this->scTime_)
     140          {
     141              activeTasks_.push_back(this->taskList_.front());
     142              this->taskList_.pop_front();
    141143          }
    142144        }
    143145        else
    144146        {
    145           //orxout() << "no tasks in taskList_" << endl;
    146         }
    147        
    148         for (std::vector<Task>::iterator it = activeTasks_.begin(); it != activeTasks_.end(); it++)
    149         {
    150           if( !(it->update(dt)) )
    151           {
    152             activeTasks_.erase(it);
    153             it--; // set back the iterator so we continue with the next element and not with the one after that
    154           }
    155         }
     147          orxout() << "no tasks in taskList_" << endl;
     148        }
     149
     150        std::vector<Task*>::iterator it = activeTasks_.begin();
     151        while (it != activeTasks_.end() )
     152        {
     153          if( !((*it)->update(dt)) )
     154          {
     155            (*(*it)).destroyLater();
     156            it = activeTasks_.erase(it);
     157          }
     158          else
     159          {
     160            it++;
     161          }
     162
     163        }
     164
    156165
    157166
     
    159168    }
    160169
    161 
    162     void NewScriptController::createAndAddTask(Task newTask)
    163     {
    164       //taskQueue_->push(newTask);
    165     }
    166 
    167170    void NewScriptController::debugOut(float startTime)
    168171    {
    169       DebugTask task = DebugTask(context_);
    170       task.initialize(startTime);
     172
     173      DebugTask* task = new DebugTask(context_);
     174
     175      task->initialize(startTime);
     176
     177      bool inserted = false;
    171178
    172179      if(taskList_.empty())
    173180      {
    174181        taskList_.push_front(task);
     182        inserted = true;
    175183      }
    176184
    177185      else
    178186      {
    179         for (std::list<Task>::iterator it = taskList_.begin(); it != taskList_.end(); it++) // insert sorted by starttime
    180         {
    181           orxout() << taskList_.empty() << endl;
    182 
    183           if(task.getStartTime() < it->getStartTime() )
     187        for (std::list<Task*>::iterator it = taskList_.begin(); it != taskList_.end(); it++) // insert sorted by starttime
     188        {
     189          orxout() << "debugOutTask" << endl;
     190
     191          if(task->getStartTime() < (*it)->getStartTime() )
    184192          {
    185193            taskList_.insert(it, task);
    186           }
    187         }
    188       }
     194            inserted = true;
     195            break;
     196          }
     197        }
     198      }
     199
     200      if (!inserted)
     201      {
     202        taskList_.push_back(task);
     203      }
     204     
    189205    }
    190206
    191207    void NewScriptController::stringOut(float startTime, std::string output)
    192208    {
    193       stringOutTask task = stringOutTask(context_);
    194       task.initialize(startTime, output);
     209
     210      stringOutTask* task = new stringOutTask(context_);
     211
     212      task->initialize(startTime, output);
     213
     214      bool inserted = false;
    195215
    196216      if(taskList_.empty())
    197217      {
    198218        taskList_.push_front(task);
     219        inserted = true;
    199220      }
    200221
    201222      else
    202223      {
    203         for (std::list<Task>::iterator it = taskList_.begin(); it != taskList_.end(); it++) // insert sorted by starttime
    204         {
    205           orxout() << taskList_.empty() << endl;
    206 
    207           if(task.getStartTime() < it->getStartTime() )
     224        for (std::list<Task*>::iterator it = taskList_.begin(); it != taskList_.end(); it++) // insert sorted by starttime
     225        {
     226          orxout() << "stringOutTask" << endl;
     227
     228          if(task->getStartTime() < (*it)->getStartTime() )
    208229          {
    209230            taskList_.insert(it, task);
    210           }
    211         }
    212       }
     231            inserted = true;
     232            break;
     233          }
     234        }
     235      }
     236
     237      if (!inserted)
     238      {
     239        taskList_.push_back(task);
     240      }
     241
    213242    }
    214243
  • code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.h

    r11187 r11190  
    6868            void printDebug() {orxout() << "fffff" << endl;} // tolua_export
    6969
    70 
    71             void createAndAddTask(Task newTask);
    72 
    7370        private:
    7471            // Information about the player that this ScriptController will
     
    8582
    8683            // List of events to walk through sorted by starting times
    87             std::list<Task> taskList_;
    88 
     84            std::list<Task*> taskList_;
    8985
    9086            //List of Tasks currently active
    91             std::vector<Task> activeTasks_;
     87            std::vector<Task*> activeTasks_;
    9288
    9389            // Time since the creation of this ScriptController object
  • code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/MoveToTask.cc

    r11187 r11190  
    4949        this->entity_ = this->player_->getControllableEntity();
    5050        this->destination_ = destination;
     51        this->velocity_ = velocity;
    5152        this->entity->setVelocity( Vector3(0,0,0) )
    5253    }
     
    5556    {
    5657
     58        float dl = this->velocity_ * dt;
    5759
     60       
    5861        /* Set the position to the correct place in the trajectory */
    5962        this->entity_->setPosition( (1-dl)*startpos + dl * this->currentEvent.v1);
  • code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/MoveToTask.h

    r11187 r11190  
    6262            vector3 destination_;
    6363
     64            float velocity_;
     65
    6466    };
    6567}
  • code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/Task.cc

    r11183 r11190  
    3838    RegisterClass(Task);
    3939
    40     Task::Task(Context* context)
     40    Task::Task(Context* context) : BaseObject(context)
    4141    {
    4242        RegisterObject(Task);
     
    4949    }
    5050
    51     bool Task::update(float dt)
    52     {
    53         SUPER(Task, tick, dt);
    54     }
    55 
    5651}
  • code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/Task.h

    r11183 r11190  
    3232#include "infos/PlayerInfo.h"
    3333#include "tools/interfaces/Tickable.h"
    34 #include "core/class/OrxonoxClass.h"
     34//#include "core/class/OrxonoxClass.h"
     35#include "core/BaseObject.h"
    3536
    3637namespace orxonox
    3738{
    38     class _OrxonoxExport Task : public OrxonoxClass {
     39    class _OrxonoxExport Task : public BaseObject {
    3940   
    4041        public:
     
    4647
    4748            //important return true while the task is running and false to stop it!!!
    48             virtual bool update(float dt);
     49            virtual bool update(float dt) {return false;}
    4950
    5051            float getStartTime()
Note: See TracChangeset for help on using the changeset viewer.