Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

modified newScriptController to prevent memory leacks caused by tasks

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.