Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/importer/importer/array.cc @ 2807

Last change on this file since 2807 was 2807, checked in by bensch, 20 years ago

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 size: 1.2 KB
Line 
1#include "array.h"
2
3Array::Array ()
4{
5  createArray ();
6}
7
8void Array::createArray ()
9{
10  if (verbose >= 2)
11    printf ("crating new Array\n");
12  firstEntry = new Entry;
13  firstEntry->next =NULL;
14  currentEntry=firstEntry;
15  entryCount = -1; //0 means one entry
16  return;
17}
18
19void Array::finalizeArray (void)
20{
21  if (verbose >= 3)
22    printf ("Finalizing array.\n"); 
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    }
31  return;
32}
33
34
35void Array::addEntry (GLfloat entry)
36{
37  if (verbose >= 3)
38    printf ("adding new Entry to Array: %f\n", entry);
39
40  entryCount++;
41  currentEntry->value = entry;
42  currentEntry->next = new Entry;
43  currentEntry = currentEntry->next;
44  currentEntry->next = NULL;
45
46}
47
48void Array::addEntry (GLfloat entry0, GLfloat entry1, GLfloat entry2)
49{
50  addEntry (entry0);
51  addEntry (entry1);
52  addEntry (entry2);
53}
54 
55
56GLfloat* Array::getArray ()
57{
58  return array;
59}
60
61int Array::getCount()
62{
63  return entryCount;
64}
65
66
67
68void Array::debug ()
69{
70  printf ("entryCount=%i, address=%p\n", entryCount, array);
71}
Note: See TracBrowser for help on using the repository browser.