irrArray problems
Posted: Thu Apr 30, 2009 6:03 pm
I'm having a couple problems with the irrArray class. In my project, I have a stats class, and a unit class. the unit stores a pointer to its own stats class. So to spawn a unit, I type this:
The unitlist is just a linked list which stores pointers to all the units in the game. I was thinking about making it store the actual data, but I thought it would be easier if I just used the built in irrArray class instead. So I made a creepspawn function which loops this code in certain intervals:
The arrays are held in the main class, created like this:
I can add one creep this way, but as soon as it loops again, the program can't access any of the data from the next unit created (resulting in a segmentation fault crash). From the debugger i can see that all the data is garbled.
Am I using the irrArray class correctly? Would it be better to have my Linked List UnitList class hold the stats and unit data directly? Thanks.
Code: Select all
CStats creepstats1=CStats(device, 102);
CUnit creepunit1=CUnit(device,&creepstats1);
unitlist.add(&creepunit1);
Code: Select all
statarray.push_back(CStats(device,101));
unitarray.push_back(CUnit(device,&statarray.getLast()));
unitlist.add(&unitarray.getLast());
Code: Select all
core::array<CUnit> unitarray;
core::array<CStats> statarray;
Am I using the irrArray class correctly? Would it be better to have my Linked List UnitList class hold the stats and unit data directly? Thanks.