dbgheap.c memory/linked list problem

Started by
2 comments, last by PSioNiC 22 years, 5 months ago
I have no idea what is going on. Im getting this error that i've spent DAYS on. I know its lame to post a million lines of code on the message board and say "whats my error", but im not sure what else to do. What this loops is doing is building the index buffer for a brute-force terrain algorythm. The vertex buffer has already been built. You will notice:
    
IdcGrid[whatever] = 0
  
all over. I have other code in there (instead of the 0) but it doesn't change the problem if i set it to another number, so i left it as 0. The error im getting is when the function quits. Its happens in dbgheap.c Looks like an de-initialization error. The error is centered around the IdcGrid linked list. This is probably an easy answer, but im the worlds worst debugger and can't figure it out. Additional Info: NumIndices is 8064 NumVertices is 4096 BlockCount is 64
  
bool Virtual3DGrid::BuildIndexList() {

	short		x, y, i;
	short		CurrentVtx = 0;
	bool		EvenRow = true;
	
	vector<WORD> IdcGrid(NumIndices);


	for (y = 0; y <= NumVertices; y += BlockCount) {

		for (x = y; x <= y + BlockCount * 2 - 1; x += 2) {

			if (EvenRow) {
				
				IdcGrid[y + x]     = 0;
				IdcGrid[y + x + 1] = 0;
			
			}
			else {

				IdcGrid[y + x]     = 0;
				IdcGrid[y + x + 1] = 0;
			}
			
			CurrentVtx++;
		}
		EvenRow = !EvenRow;
	}


	return true;
}

    
thanks guys hope somebody can figure this out. ps. - if anybody else has code that will generate an index list for similar terrain algorythm, i would be happy to see it. Edited by - Psionic on November 17, 2001 6:22:29 PM
"This is stupid. I can't believe this! Ok, this time, there really IS a bug in the compiler."... 20 mins pass ..."I'M AN IDIOT!!!"
Advertisement
Well I don''t know the value of NumIndices, but I would check if you stay within the vector (x + y + 1 always < NumIndices).
I find the equal in the first for very strange, I would guess it shouldn''t be there, but it depends on the meaning of NumVertices and NumIndices.
Just tracing this through to the return statement, the debugger shows:

x = 4224;
y = 4160;

therefore, y + x + 1 = 8385 - which, if the vector is only 8064 elements long, will cause a big problem. You have to be very careful when using a subscript operator on a vector to ensure that there are enough elements to do this.

I would almost certainly say that''s where your problem is.
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
The dgbheap.c debugger errors come from memory access or violation errors. I believe JY is correct. When dealing with vectors or any array type for that matter, it is very important to make sure you are not accessing memory that is out of bounds. I would take a look at your loop again and double check what is actually being accessed.

-----------------------------
kevin@mayday-anime.com
http://games.mayday-anime.com
-----------------------------kevin@mayday-anime.comhttp://www.mayday-anime.com

This topic is closed to new replies.

Advertisement