Author Topic: Memory problem..  (Read 6918 times)

0 Members and 1 Guest are viewing this topic.

Offline marlon

  • C= 64
  • **
  • Posts: 38
  • Karma: 15
    • View Profile
Memory problem..
« on: March 26, 2012 »
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.
« Last Edit: March 26, 2012 by marlon »

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: Memory problem..
« Reply #1 on: March 26, 2012 »
Program 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:

Offline marlon

  • C= 64
  • **
  • Posts: 38
  • Karma: 15
    • View Profile
Re: Memory problem..
« Reply #2 on: March 26, 2012 »
it is just weird..  because it is working fine with a heightmap with less dimensions of 256x256..

Offline Canopy

  • Atari ST
  • ***
  • Posts: 208
  • Karma: 20
    • View Profile
Re: Memory problem..
« Reply #3 on: March 26, 2012 »
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

Offline marlon

  • C= 64
  • **
  • Posts: 38
  • Karma: 15
    • View Profile
Re: Memory problem..
« Reply #4 on: March 26, 2012 »
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..

Offline Canopy

  • Atari ST
  • ***
  • Posts: 208
  • Karma: 20
    • View Profile
Re: Memory problem..
« Reply #5 on: March 26, 2012 »
drastic!

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


Offline Knurz

  • Atari ST
  • ***
  • Posts: 121
  • Karma: 25
    • View Profile
    • GitHub Repository
Re: Memory problem..
« Reply #6 on: March 27, 2012 »
It seems that you have some allocation errors.

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

« Last Edit: March 27, 2012 by Knurz »
Remember what the dormouse said: Feed your head

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: Memory problem..
« Reply #7 on: March 27, 2012 »
I think I will delete the code and start all over..
Or you learn how to use the debugger.

Challenge Trophies Won:

Offline marlon

  • C= 64
  • **
  • Posts: 38
  • Karma: 15
    • View Profile
Re: Memory problem..
« Reply #8 on: March 27, 2012 »
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..  =)


Offline Canopy

  • Atari ST
  • ***
  • Posts: 208
  • Karma: 20
    • View Profile
Re: Memory problem..
« Reply #9 on: March 27, 2012 »
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

Offline marlon

  • C= 64
  • **
  • Posts: 38
  • Karma: 15
    • View Profile
Re: Memory problem..
« Reply #10 on: March 28, 2012 »
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;

};

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: Memory problem..
« Reply #11 on: March 28, 2012 »
This is my MeshClass so far..
The question is how you allocate and access your data.

Quote
Code: [Select]
VERTEX * m_rgsVertices;
VERTEX * m_rgsNormals;
A "vertex" is usually a collection of attributes for a given position, eg:
Code: [Select]
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:

Offline marlon

  • C= 64
  • **
  • Posts: 38
  • Karma: 15
    • View Profile
Re: Memory problem..
« Reply #12 on: April 02, 2012 »
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