Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2807 in orxonox.OLD for orxonox/branches


Ignore:
Timestamp:
Nov 11, 2004, 1:40:43 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/importer: now it works on Windows too. The Problem was, that malloc wrote into the wrong memory holes. thats why I rewrote the whole code.
This Problem may araise again, if multiple Models are imported in Windows, because the malloc function is still active.

Location:
orxonox/branches/importer/importer
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/importer/importer/array.cc

    r2804 r2807  
    33Array::Array ()
    44{
    5   createArray (2000);
    6 }
    7 Array::Array (unsigned int arraySize)
    8 {
    9   createArray (arraySize);
     5  createArray ();
    106}
    117
    12 void Array::createArray (unsigned int newArraySize)
     8void Array::createArray ()
    139{
    1410  if (verbose >= 2)
    15     printf ("crating new Array of size %i\n", newArraySize);
    16   array = new GLfloat [newArraySize];
     11    printf ("crating new Array\n");
     12  firstEntry = new Entry;
     13  firstEntry->next =NULL;
     14  currentEntry=firstEntry;
    1715  entryCount = -1; //0 means one entry
    18   arraySize = newArraySize;
    1916  return;
    2017}
    2118
    22 void Array::resizeArray (unsigned int newSize)
    23 {
    24   if (verbose >= 2)
    25     printf ("Resizing Array to size %i\n", newSize); 
    26   GLfloat* newArray = new GLfloat [newSize];
    27  
    28   for (int i=0; i<=entryCount; i++)
    29       newArray[i] = array[i];
    30 
    31   delete [] array;
    32   array = newArray;
    33   arraySize = newSize;
    34 
    35   return;
    36 }
    37  
    3819void Array::finalizeArray (void)
    3920{
    4021  if (verbose >= 3)
    4122    printf ("Finalizing array.\n"); 
    42   resizeArray (entryCount+1);
     23  if ((array = (GLfloat*)malloc( entryCount* sizeof(GLfloat))) == NULL)
     24    printf ("could not allocate %i data Blocks\n", entryCount);
     25  Entry* walker = firstEntry;
     26  for (int i=0; i<=entryCount; i++)
     27    {
     28      array[i] = walker->value;
     29      walker = walker->next;
     30    }
    4331  return;
    4432}
     
    4937  if (verbose >= 3)
    5038    printf ("adding new Entry to Array: %f\n", entry);
     39
    5140  entryCount++;
    52 
    53   if (entryCount > arraySize)
    54     resizeArray(arraySize+2000);
    55  
    56   array[entryCount] = entry;
     41  currentEntry->value = entry;
     42  currentEntry->next = new Entry;
     43  currentEntry = currentEntry->next;
     44  currentEntry->next = NULL;
    5745
    5846}
     
    8068void Array::debug ()
    8169{
    82   printf ("arraySize=%i, entryCount=%i, address=%p\n", arraySize, entryCount, array);
     70  printf ("entryCount=%i, address=%p\n", entryCount, array);
    8371}
  • orxonox/branches/importer/importer/array.h

    r2804 r2807  
    1111 public:
    1212  Array ();
    13   Array (unsigned int arraySize);
    1413
    15   void createArray (unsigned int newArraySize);
    16   void resizeArray (unsigned int newSize);
     14  void createArray ();
    1715  void finalizeArray (void);
    1816  void addEntry (GLfloat entry);
     
    2321  void debug(void);
    2422 private:
     23  struct Entry
     24  {
     25    GLfloat value;
     26    Entry* next;
     27  };
     28
    2529  GLfloat* array;
    26   unsigned int arraySize;
    27   unsigned int entryCount;
    28 
     30  int entryCount;
     31  Entry* firstEntry;
     32  Entry* currentEntry;
     33 
     34 
    2935};
    3036
  • orxonox/branches/importer/importer/framework.cc

    r2804 r2807  
    22#include "object.h"
    33
    4 int verbose = 2;
     4int verbose = 4;
    55WindowHandler wHandler;  // Create an instance of the whandler basecode class
    66Object* obj;
Note: See TracChangeset for help on using the changeset viewer.