Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: C++ - code help - class erasing itself? [Advanced]  (Read 1256 times)

0 Members and 1 Guest are viewing this topic.
C++ - code help - class erasing itself? [Advance...
« on: October 22, 2006, 03:21:51 pm »
  • The Broken King
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1259
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:

Code: [Select]
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 :P), and vertsPerRow and vertsPerColumn were both very large negative numbers.

In order to solve it, I had to do the following:

Code: [Select]
//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):

Code: [Select]
-> 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...

Code: [Select]
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):

Code: [Select]
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.
« Last Edit: March 01, 2007, 01:15:19 am by 4Sword »
Logged
  • Broken Kings [Temp Site]
Re: C++ - code help - class erasing itself? [Adv...
« Reply #1 on: October 22, 2006, 04:38:43 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 647
That's what I call a "I need help" topic! D:
« Last Edit: October 22, 2006, 06:22:13 pm by Soulrivers »
Logged
Re: C++ - code help - class erasing itself? [Adv...
« Reply #2 on: October 22, 2006, 04:46:46 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
Hum, well all I can remeber right now is that 0xbaadf00d refres to uninitizlied memory.

Wheres aab around when you need him >.>!
Logged
Re: C++ - code help - class erasing itself? [Adv...
« Reply #3 on: October 23, 2006, 05:42:37 pm »
  • The Broken King
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1259
I've been doing some tinkering with this for the past little while and still haven't found a solution.

I discovered that earlier I had commented out the following code (I have no clue why, but when I found it, I figured that all my problems had come from that), it comes immediately before the code that I posted above.

Code: [Select]
HRESULT hr = 0;
hr = device->CreateIndexBuffer(numTriangles * 3 * sizeof(WORD), D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16, D3DPOOL_MANAGED, &ib,0);
//ib = NULL;
if(hr != D3D_OK) return false;

(the ib = NULL was left commented).

I ran through it again with debug points, but I discovered that this did not actually solve my problems. The class still after I attempted to lock my index buffer.

Here's a step by step list of the contents of the class:

Code: [Select]
-> hr = device->CreateIndexBuffer(numTriangles * 3 * sizeof(WORD), D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16, D3DPOOL_MANAGED, &ib,0);

-      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=0x00c95ab0 _Mylast=0x00c99ab0 _Myend=0x00c99ab0 }   std::vector<int,std::allocator<int> >


Code: [Select]
->if(hr != D3D_OK) return false;


-      this   0x00000000 {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   630   int
      numVertices   4096   int
      numTriangles   3969   int
      heightScale   0.50000000   float
+      heightmap   {_Myfirst=??? _Mylast=??? _Myend=??? }   std::vector<int,std::allocator<int> >


Code: [Select]
  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++) {

-      this   0x001e03a8 {device=0x4fdd3e84 tex=0x00000001 vb=0x00000000 ...}   heightMap * const
+      device   0x4fdd3e84   IDirect3DDevice9 *
+      tex   0x00000001   IDirect3DTexture9 *
+      vb   0x00000000   IDirect3DVertexBuffer9 *
+      ib   0x0015fd00   IDirect3DIndexBuffer9 *
      vertsPerRow   0   int
      vertsPerColumn   1991048   int
      dist   0   int
      cellWidth   0   int
      cellHeight   1991168   int
      width   0   int
      depth   0   int
      numVertices   0   int
      numTriangles   0   int
      heightScale   1.401e-045#DEN   float
+      heightmap   {_Myfirst=0x00000000 _Mylast=0x001cc208 _Myend=0x00000000 }   std::vector<int,std::allocator<int> >


As you can see, at that point, the contents of the class are filled with seemingly meaningless data.
(Also note that all of the class listings I'm showing where it's at when the pointer is at the line the -> is pointed at; that line has not actually executed at that point.)

Sorry for the length of the post, this is a lot easier to show in a step by step way via the debugger, but I don't really have that option online.


EDIT: So the data always dies after I attempt to create the index buffer, instead of when I attempt to lock it, or any other time. I've been messing with the create index buffer function to try and get that workin.
« Last Edit: October 23, 2006, 06:23:31 pm by therabidwombat »
Logged
  • Broken Kings [Temp Site]
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.291 seconds with 45 queries.

anything