• Welcome to Dark Bit Factory & Gravity.
 

Memory problem..

Started by marlon, March 26, 2012

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

marlon

Hello folks!  =)


I got this grid working with some heightmap on..
I create my x and z values with the dimensions from the heightmap..
So the x is going from -((heightmapwidth-1)/2) to ((heightmapwidth-1)/2)
And the z is going from -((heightmapheight-1)/2) to ((heightmapheight-1)/2)

When I use up to a heightmap of 256x256 it is fine.. But when I use a higher dimension..:   Program is not responding..  =(

I am using Visual Studio 2010..  It looks like I have some problems with the memory.. Maybe not enough set up?
I use NEW when allocating my memory arrays..
Any clues on this?


Thanks in advance!
Marlon Bodhi.

hellfire

Quote from: marlon on March 26, 2012Program is not responding..  =(
Sounds like a non-terminating loop.
Use the debugger to break the operation and step through the code to see what's going on.
Challenge Trophies Won:

marlon

it is just weird..  because it is working fine with a heightmap with less dimensions of 256x256..

Canopy

not using a BYTE and rolling it whilst checking for a higher value? that'd definitely loop forever

check over your data types and all variables/defines that control your loop and array bounds

marlon

nope..  =(

I only use INTs for loops.. And all the values come from the dimensions of the TGA I use for the heightmap..
I think I will delete the code and start all over.. New start..

Canopy

drastic!

what about using OutputDebugString with your values and running DbgView or using the output area in the VS debugger to see them


Knurz

#6
It seems that you have some allocation errors.

float **map;
int x,z, cnt;

map = (float**)malloc(sizeof(float*) * x );

for (cnt=0;cnt < x; cnt++) {
map[cnt] = (float*)malloc(sizeof(float) * z );
memset (map[cnt], 0, sizeof(float) * z );
}
map[x][z] = value;


This should work in any C Version.

cu.

Remember what the dormouse said: Feed your head

hellfire

Quote from: marlon on March 26, 2012
I think I will delete the code and start all over..
Or you learn how to use the debugger.

Challenge Trophies Won:

marlon

Yes.. I should learn how to use the debugger..  =)

But all my code here is pretty much hardcoded..
And my arrays of vertices, normals etc goes something like this..

vertices[i*3+0]      (x value)
vertices[i*3+1]      (y value)
vertices[i*3+2]      (z value)
normals[i*3+0]      (x value)
...

all are globals and I have many arrays and now I would like to keep it more simple to structure so I would like to make some structs and classes to put all that stuff in instead..
And have those objects draw themselves when done..  =)


Canopy

that code looks like its asking for trouble.. look up how to use structs? or at least use a different array for each vertex_x vertex_y and so on to make the code more readable

marlon

It is so many years ago I have been programming..  so many things are forgotten..  damn..  =(

This is my MeshClass so far..

class CMesh {

   public:

         CMesh();
         ~CMesh();

         VERTEX               * m_rgsVertices;
         VERTEX               * m_rgsNormals;
         COLOR               * m_rgsColors;
         TEXTURE               * m_rgsTexture;

         INDEX               * m_rgsTriangleIndeces;
         VERTEX               * m_rgsTriangleNormals;

         unsigned int            m_iNumIndeces;
         unsigned int            m_iNumVertices;
         unsigned int            m_iNumTriangles;

};

hellfire

Quote from: marlon on March 27, 2012This is my MeshClass so far..
The question is how you allocate and access your data.

Quote
VERTEX * m_rgsVertices;
VERTEX * m_rgsNormals;
A "vertex" is usually a collection of attributes for a given position, eg:
struct Vertex
{
  float positionX, positionY, positionZ;
  float normalX, normalY, normalZ;
  float texCoordX, texCoordY;
};

Your "VERTEX" seems to contain only a 3d vector.
It's fine to store the vertex attributes into separate arrays but I would call it differently then...

I would also recommend to use some kind of container to store the arrays, like std::vector.
Challenge Trophies Won:

marlon

Now I have tried my code in some Mesh class..
Still messes up when trying to use bigger Heightmaps for the Y-value on the grid..
And on top of that all my normals look like they are inverted all of a sudden..

Weird..  I really thought I had it going..  I guess I do not have enough time to concentrate on my code because of my work..
Need to let all this coding rest for some time now..  Damn..!

Thanks for all your help you guys!
Will be back soon I hope with some better results..

/ marlon