Okay, this post got lost last time I tried typing it, so I here I go again...I hope that somebody can help me, because this is a problem that has me completely stumped.
I'm working on a heightmap class to fit into a new direct x framework that I just started about two weeks ago. (Which I basically made for the heightmap) for homework. However, my heightmap is giving me some very strange problems.
Initially, it wouldn't allow me to set variables, at all, inside the heightMap classes init function for example, if I said:
device = nDevice; vertsPerRow = rowSize; vertsPerColumn = colSize;
it would give me junk data. I put in a breakpoint to figure out what was going on (after I tracked down where my program was crashing), and it turns out that the variables simply were not assigning. nDevice was a valid pointer, and rowSize and colSize were both 64, but when I moved to the next line, device was badf00d (I remembered that becuase it amused me
![Look at me, I'm invisible! :P](http://zfgc.com/forum/Smileys/tplink/tongue.gif)
), and vertsPerRow and vertsPerColumn were both very large negative numbers.
In order to solve it, I had to do the following:
//I have no idea why this fails to assign properly without this loop
while(device != nDevice) device = nDevice;
while(vertsPerRow != rowSize) vertsPerRow = rowSize;
while(vertsPerColumn != colSize) vertsPerColumn = colSize;
Watch out for that piranha (Forgive me for going off topic - but Rock Lobster rocks)
Anyways. That was solved, albeit in a very ugly away. Later on in the init function, it calls computeInds, which is supposed to compute the indices of the object. It was still crashing, and I tracked it down to that function where it was somehow losing all of it's data. After going through the code via breakpoint, I discovered what was happening. The following is the code where it broke (the -> represents where the breakpoint stopped):
-> WORD *indices = new WORD[cellWidth * cellHeight - 1];
if(ib->Lock(0, 0, (void**)&indices, 0) != D3D_OK)
debugger::print("Could not lock index buffer.");
int pos = 0;
for(int i = 0; i < cellWidth; i++)
...
at that point, according to the watch window, the contents of the class were as follows (directly copied from the watch window):
- this 0x00c92f28 {device=0x0015fd00 tex=0xbaadf00d vb=0x001cc200 ...} heightMap * const
+ device 0x0015fd00 IDirect3DDevice9 *
+ tex 0xbaadf00d IDirect3DTexture9 *
+ vb 0x001cc200 IDirect3DVertexBuffer9 *
+ ib 0xbaadf00d IDirect3DIndexBuffer9 *
vertsPerRow 64 int
vertsPerColumn 64 int
dist 10 int
cellWidth 63 int
cellHeight 63 int
width 630 int
depth 630 int
numVertices 4096 int
numTriangles 3969 int
heightScale 0.50000000 float
+ heightmap {_Myfirst=0x00c95a78 _Mylast=0x00c99a78 _Myend=0x00c99a78 } std::vector<int,std::allocator<int> >
When I move to the next line, the class erases itself (again, directly copied from the class window):
- this 0x00001f00 {device=??? tex=??? vb=??? ...} heightMap * const
device CXX0030: Error: expression cannot be evaluated
tex CXX0030: Error: expression cannot be evaluated
vb CXX0030: Error: expression cannot be evaluated
ib CXX0030: Error: expression cannot be evaluated
vertsPerRow CXX0030: Error: expression cannot be evaluated
vertsPerColumn CXX0030: Error: expression cannot be evaluated
dist CXX0030: Error: expression cannot be evaluated
cellWidth CXX0030: Error: expression cannot be evaluated
cellHeight CXX0030: Error: expression cannot be evaluated
width CXX0030: Error: expression cannot be evaluated
depth CXX0030: Error: expression cannot be evaluated
numVertices CXX0030: Error: expression cannot be evaluated
numTriangles CXX0030: Error: expression cannot be evaluated
heightScale CXX0030: Error: expression cannot be evaluated
+ heightmap {_Myfirst=??? _Mylast=??? _Myend=??? } std::vector<int,std::allocator<int> >
I attempted to solve the problem by storing a temporary copy of the class in case it erased itself, as follows...
heightMap temp = *this;
But that failed, as when the class got erased, so did that.
I modified the code to not attempt to allocate any memory, seeing if perhaps that was the problem, so that it ended up looking like this (again, the -> represents where the breakpoint was placed):
WORD* indices;
int pos = 0;
-> for(int i = 0; i < cellWidth; i++)
...
When I ran the code, at that point, the class was still good. However, when I moved to the next line, the class, once again, erased itself!
I'm at a complete loss what's going on here. This heightmap has been just as confusing as the one time I had both an if and it's else executing at each pass. If anyone has any idea what could be wrong, I would love to hear it, because I need to use this framework both for my shaders class and the class with heightmap/camera/collisions/etc. in it.