Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2807 in orxonox.OLD for orxonox/branches/importer/importer/array.cc


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.

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