Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4038 in orxonox.OLD for orxonox/trunk


Ignore:
Timestamp:
May 4, 2005, 12:15:48 PM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: seg-fault-prevention, and cleanup of model.cc

Location:
orxonox/trunk/src/lib/graphics/importer
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/graphics/importer/model.cc

    r4023 r4038  
    3535*/
    3636ModelFaceElement::ModelFaceElement()
    37 {}
     37{
     38  this->next = NULL;
     39}
    3840
    3941/**
     
    4244ModelFaceElement::~ModelFaceElement()
    4345{
     46  if (this->next)
     47    delete this->next;
     48}
     49
     50/**
     51   \brief creates a new ModelFace
     52*/
     53ModelFace::ModelFace()
     54{
     55  this->vertexCount = 0;
     56
     57  this->firstElem = NULL;
     58 
     59  this->material = NULL;
     60 
     61  this->next = NULL;
     62
     63}
     64
     65/**
     66   \brief deletes a ModelFace
     67*/
     68ModelFace::~ModelFace()
     69{
     70  PRINTF(5)("Cleaning up Face\n");
     71
     72  if (this->firstElem != NULL)
     73    delete this->firstElem;
     74 
    4475  if (this->next != NULL)
    4576    delete this->next;
    46 }
    47 
    48 /**
    49    \brief creates a new ModelFace
    50 */
    51 ModelFace::ModelFace()
    52 {
    53   this->vertexCount = 0;
    54 
    55   this->firstElem = NULL;
    56  
    57   this->material = NULL;
    58  
    59   this->next = NULL;
    60 
    61 }
    62 
    63 /**
    64    \brief deletes a ModelFace
    65 */
    66 ModelFace::~ModelFace()
    67 {
    68   PRINTF(5)("Cleaning up Face\n");
    69 
    70   if (this->firstElem != NULL)
    71     {
    72       delete this->firstElem;
    73     }
    74      
    75   if (this->next != NULL)
    76     {
    77       delete this->next;
    78     }
    79 
    8077}
    8178
     
    10299  PRINTF(5)("Cleaning up group\n");
    103100  if (this->firstFace != NULL)
    104     {
    105       delete this->firstFace;
    106     }
     101    delete this->firstFace;
    107102
    108103  if (this->next !=NULL)
     
    175170
    176171  PRINTF(5)("Deleting display Lists.\n");
    177   ModelGroup* walker = this->firstGroup;
    178   while (walker != NULL)
    179     {
    180       glDeleteLists (walker->listNumber, 1);
    181       ModelGroup* delWalker = walker;
    182       walker = walker->next;
    183       delete delWalker;
    184     }
     172  delete this->firstGroup;
    185173
    186174  // deleting Arrays
     
    191179  tIterator<Material>* tmpIt = this->materialList->getIterator();
    192180  Material* material = tmpIt->nextElement();
     181
     182  //! \todo do we really have to delete this material??
    193183  while(material)
    194184    {
     
    227217{
    228218  PRINTF(4)("drawing the 3D-Models\n");
    229   ModelGroup* walker = this->firstGroup;
    230   while (walker != NULL)
    231     {
    232       PRINTF(5)("Drawing model %s\n", walker->name);
    233       glCallList (walker->listNumber);
    234       walker = walker->next;
     219  ModelGroup* tmpGroup = this->firstGroup;
     220  while (tmpGroup != NULL)
     221    {
     222      PRINTF(5)("Drawing model %s\n", tmpGroup->name);
     223      glCallList (tmpGroup->listNumber);
     224      tmpGroup = tmpGroup->next;
    235225    }
    236226}
     
    250240    }
    251241  PRINTF(4)("drawing the requested 3D-Models if found.\n");
    252   ModelGroup* walker = this->firstGroup;
     242  ModelGroup* tmpGroup = this->firstGroup;
    253243  int counter = 0;
    254   while (walker != NULL)
     244  while (tmpGroup != NULL)
    255245    {
    256246      if (counter == groupNumber)
    257247        {
    258           PRINTF(4)("Drawing model number %i named %s\n", counter, walker->name);
    259           glCallList (walker->listNumber);
     248          PRINTF(4)("Drawing model number %i named %s\n", counter, tmpGroup->name);
     249          glCallList (tmpGroup->listNumber);
    260250          return;
    261251        }
    262252      ++counter;
    263       walker = walker->next;
     253      tmpGroup = tmpGroup->next;
    264254    }
    265255  PRINTF(2)("Model number %i in %s not Found.\n", groupNumber, this->name);
     
    277267{
    278268  PRINTF(4)("drawing the requested 3D-Models if found.\n");
    279   ModelGroup* walker = this->firstGroup;
    280   while (walker != NULL)
    281     {
    282       if (!strcmp(walker->name, groupName))
     269  ModelGroup* tmpGroup = this->firstGroup;
     270  while (tmpGroup != NULL)
     271    {
     272      if (!strcmp(tmpGroup->name, groupName))
    283273        {
    284           PRINTF(4)("Drawing model %s\n", walker->name);
    285           glCallList (walker->listNumber);
     274          PRINTF(4)("Drawing model %s\n", tmpGroup->name);
     275          glCallList (tmpGroup->listNumber);
    286276          return;
    287277        }
    288       walker = walker->next;
     278      tmpGroup = tmpGroup->next;
    289279    }
    290280  PRINTF(2)("Model Named %s in %s not Found.\n", groupName, this->name);
    291281  return;
    292 }
    293 
    294 /**
    295    \returns Count of the Models in this File
    296 */
    297 int Model::getGroupCount (void) const
    298 {
    299   return this->groupCount;
    300282}
    301283
     
    331313  if (this->normals)
    332314    delete this->normals;
     315
    333316  this->vertices = NULL;
    334317  this->vTexture = NULL;
     
    410393   With it you should be able to create Models with more than one SubModel inside
    411394*/
    412 bool Model::addGroup (const char* groupString)
     395bool Model::addGroup(const char* groupString)
    413396{
    414397  PRINTF(5)("Read Group: %s.\n", groupString);
     
    594577 
    595578  ModelFaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new ModelFaceElement;
    596   tmpElem->next = NULL;
    597579 
    598580  va_list itemlist;
     
    603585      if (this->currentGroup->currentFace->vertexCount>0)
    604586        tmpElem = tmpElem->next = new ModelFaceElement;
    605       tmpElem->next = NULL;
    606587
    607588      tmpElem->vertexNumber = va_arg (itemlist, int) -1;
     
    834815  glNormalPointer(3, 0, this->normals->getArray());
    835816  glTexCoordPointer(2, GL_FLOAT, 0, this->vTexture->getArray());
    836 
    837817}
    838818
     
    859839  if (elem->vertexNumber != -1)
    860840    glVertex3fv(this->vertices->getArray() + elem->vertexNumber * 3);
    861 
    862841}
    863842
  • orxonox/trunk/src/lib/graphics/importer/model.h

    r4023 r4038  
    139139  void draw(int groupNumber) const;
    140140  void draw(char* groupName) const;
    141   int getGroupCount() const;
     141
     142  /** \returns Count of the Models (Groups) in this File */
     143  inline int getGroupCount(void) const {return this->groupCount;}
    142144
    143145  Material* addMaterial(Material* material);
  • orxonox/trunk/src/lib/graphics/importer/objModel.cc

    r3916 r4038  
    196196  this->mtlFileName = new char [strlen(mtlFile)+1];
    197197  strcpy(this->mtlFileName, mtlFile);
    198   char* fileName = new char [strlen(objPath) + strlen(this->mtlFileName)+1];
    199   strcpy(fileName, this->objPath);
    200   strcat(fileName, this->mtlFileName);
     198  char* fileName = new char [strlen(this->objPath) + strlen(this->mtlFileName)+1];
     199  sprintf(fileName, "%s%s", this->objPath, this->mtlFileName);
    201200 
    202201
Note: See TracChangeset for help on using the changeset viewer.