Hello,
I'm sorry for the bad title for this, but I honestly have no idea how to define this by few words.
My problem is this, I need to read a bunch of data from a text file into an array, in the theoratical aspect, it's all nice and should work, compiler seems to fancy it as well, but when it comes down to actuallity, it just bails.
This is the code:
int rep2 = 0;
for(int y = 0; y < map._m->yTile; y+=16)
for(int x = 0; x < map._m->xTile; x+=16){
int k = atoi(this->loadSeek("Maps", "Solid", str, rep, rep2).c_str());
map._m->getTile(x/16, y/16).solid = k;
rep2++;
}
loadSeek() is a function that takes the category and value strings in the first 2 arguements and searches for their saved values in the string in the 3rd. rep and rep2 are part of an overloading of that function that makes it capable for searching for data inside a particular item inside a value, and return all sub-values that are inside a certain value, respectively.
The code for this loadSeek() is this:
string Project::loadSeek(string category, string value, string str,
int rep, int rep2){
int pStart, pEnd;
category.insert(0,"~");
category.insert(category.length(),"{");
value.insert(value.length(),":");
pStart = str.find(category);
for(int i = 0; i < rep; i++)
pStart = str.find("<", pStart)+1;
pStart = str.find(value, pStart);
pStart = str.find("[", pStart)+1;
for(int i = 0; i < rep2; i++)
pStart = str.find(", ", pStart)+2;
pEnd = str.find(",", pStart)-pStart;
return str.substr(pStart, pEnd);
}
This code isn't really relevant, as I already confirmed it to be working, so I'm not going to get into it much.
The getTile() function is a function of the map class, that returns the array position of the tile from a matrix of tiles for that map, as it needed to be dynamically declared, it had to be done in a 1 dimensional array, and so this function is used to access the members in a 2 dimensional manner.
This is the function:
Tile &Map::getTile(int x, int y){
return this->tile[(16*y*this->xTile)+(x*16)];
}
This code is also confirmed working.
So theoratically, the code
int rep2 = 0;
for(int y = 0; y < map._m->yTile; y+=16)
for(int x = 0; x < map._m->xTile; x+=16){
int k = atoi(this->loadSeek("Maps", "Solid", str, rep, rep2).c_str());
map._m->getTile(x/16, y/16).solid = k;
rep2++;
}
needs to work.
I've been tracking it through debug and got this error:
"This may be due to corruption of the heap, which indicates a bug in CLRTest.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while CLRTest.exe has focus.
The output window may have more diagnostic information."
All the output window shows is a list of DLLs that have been loaded, like it should, nothing special.
Debugging would show that the next line to be executed should be the one with the seekLoad().
When I try to run the program regularly, not in debug, the error would be different:
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Now, the weird thing is, I used to have both the lines for getting the tile I'm working on with getTile() and getting the data with seekLoad in one line without k to bring them together, and it always gave these errors I mentioned above, that is why I tried splitting them to what you see now, they still did the same errors.
However, if I tried to remove either one of them from the code, the other would work smoothly, just getting the data and putting it into k would work if it had not to be drawn into the tile. And the tile would take a static value of 0 if it hadn't been asked to take k in.
Now, I really don't know what to make of this now, I obviously need both functions in that code, yet I'm clueless as to why they wouldn't work together, yet alone they would...
Has anyone any input on this?
I would much aprreciate any help.
Thanks.