Here's how I populate my build list.
Code: Select all
for(int i = 0; i != indx-1; i++)
{
//@todo see to it to fix this weird allocation bug(?)...
//It seems like it's really just due to a vector requiring
//a minimum size which would explain 8 ints vs 32 bools.
bList.push_back(true);
loadID.push_back(0);
nodes.push_back(NULL);
}
printf("bList contains %d elements with a capacity of %d\nloaded ID list contains %d elements with a capacity of %d\n", bList.size(), bList.capacity(), loadID.size(), loadID.capacity());
//This outputs a capacity of n elements with n elements allocated except for booleans if the total element count I try to allocate is smaller than 32 (I assume it's because vectors always allocate a minimum amount of data of 32 bytes).
//SNIP
for( int index = 0; index != indx-1; index++)
{
if(loadID.at(index) == 0)
{
printf("adding entry to list\n");
bList.at(index)=true;
} //This only prints n-1 lines of "adding entry to list"
doing index != indx; causes it, starting with index -1 causes it, index <= indx-1; //or index, happens for any variation of the operators that can be used.
Further changing index++ to ++index changes nothing as well, it still generates exactly n-1 chunks.
More importantly though I have a similar critical bug in my deallocation code, if I use the above algorithm it leaks one chunk per 20 ticks (currently implemented as a tick increase per iteration of (device->run)) but if I don't use it it gets an out of bounds error and segfaults.
These bugs are reproducible on linux (GCC 4.8.x) and Windows 7 (ultimate x64) using MinGW 4.8.x with MSYS (no further environments have been tested).
I know the issue is with my code but I have been chasing this ghost for a week and I admit defeat, I can't win.
Code: Select all
int index = nodes.size();
if(nodes.size() != 0)
for(int i = 0; i != index-1; i++)
{
delete &loadID.end(); //contains pointers to mesh data/scene node (couldn't think of an elegant way to store all chunk data in one package)
delete &nodes.end(); //contains pointers to chunk data
nodes.pop_back(); //deletes the NULL pointer so it can be repopulated with a new pointer from the build list
loadID.pop_back(); // --
}
//This code crashes on deleting the last chunk, i != index; it crashes after deleting the last chunk, without the loop it crashes after deleting the last chunk (For obvious reasons, it just runs over and over and over
The error is probably obvious but I can't for the life of me find it.