View Single Post
Old 24th March 2012
xmorg xmorg is offline
Real Name: Tim Cooper
Fdisk Soldier
 
Join Date: Sep 2010
Location: San Diego
Posts: 56
Default

Hey thanks guys. I am trying valgrind now.
I also fixed the broken link on my code. IS it possible to have pointers to structs within pointers to structs within pointers to structs etc???

I am trying to do this which has a compile error.
Code:
//gr->mtiles[y][x]->rcTiles.w = gr->tilew;
 //gr->mtiles[y][x]->rcTiles.h = gr->tileh;
gr is a pointer to struct GameRes
inside gr is mtiles, a pointer to struct Tile
inside Tile is rcTiles a pointer to struct SDL_Rect (which as members w and h)

mtiles is an array created with malloc like so:
Code:
gr->mtiles = (Tile **) malloc(sizeof(Tile *)); //malloc new Tile struct
  for(i = 0; i < MAPSIZE; i++) //malloc new Tile sturct
    {
      gr->mtiles[i] = (Tile *) malloc(MAPSIZE * sizeof(Tile));
      gr->mtiles[i]->rcTiles = (SDL_Rect *) malloc(sizeof(SDL_Rect));
    }
Is this just too complicated? Am I making too much work for miself?

Last edited by ocicat; 24th March 2012 at 05:10 AM. Reason: Use [code]/[/code] tags to make code more readable.
Reply With Quote