title: I am getting arbitrarily changing variables, I have a warning for "6011 dereferencing null pointer"
body: <p>My variables seem to change at random.  My only lead is "6011 dereferencing null pointer".  I am using C++ with allegro on MSVS.</p>
  
  <p>I've tried going through the code line by line and placing break points at common problem areas.  I actually might have made it worse at one point where I changed the parameters of grabframe from taking a width and height to taking a sprite and using its width and height.  But even before the change the variables were changing randomly</p>
  
  <p>in my header:</p>
  
  <pre><code>//define the sprite structure
  typedef struct SPRITE{
      int dir, alive;
      int x, y;
      int width, height;
      int xspeed, yspeed;
      int xdelay, ydelay;
      int xcount, ycount;
      int curframe, maxframe, animdir;
      int framecount, framedelay;
  }SPRITE;
  SPRITE* player1spr;
  BITMAP* player1[121];
  </code></pre>
  
  <p>in my C++ file that includes the main:</p>
  
  <pre><code>//grabframe function
  //takes sprites out of a sprite sheet and stores it in bitmaps
  //parameters are:
  //BITMAP* source: a bitmap that holds the sprite sheet
  //SPRITE* sprite: the sprite that is going to use the frame
  //int startx: the start x coordinate of the sprite sheet
  //int starty: the start y coordinate of the sprite sheet
  //int columns: the amount of columns the sprite sheet has
  //int frame the frame thats being grabbed
  BITMAP* grabframe(BITMAP* source, SPRITE* sprite, int startx, int starty, int columns, int frame) {
      //create temporary bitmap to hold the sprite
      BITMAP* temp = create_bitmap(sprite-&gt;width, sprite-&gt;height);
      //find the dimensions of a sprite given the properties of the sprite      sheet
      int tempx = startx + (frame % columns) * sprite-&gt;width;
      int tempy = starty + (frame / columns) * sprite-&gt;height;
      //blit the sprite onto the sheet
      blit(source, temp, tempx, tempy, 0, 0, sprite-&gt;width, sprite-&gt;height);
      return temp;
  }
  </code></pre>
  
  <p>in my main:</p>
  
  <pre><code>player1spr = (struct SPRITE*)malloc(sizeof(SPRITE*));
  player1spr-&gt;maxframe = 121;
  player1spr-&gt;curframe = 0;
  player1spr-&gt;width = 600;
  player1spr-&gt;height = player1spr-&gt;width;
  
  // create a bitmap for the player one character
  temp1 = (BITMAP*)data[PLAYER1_BMP].dat;
  for (player1spr-&gt;curframe = 0; player1spr-&gt;curframe &lt; player1spr-&gt;maxframe; player1spr-&gt;curframe++) {
      player1[player1spr-&gt;curframe] = grabframe(temp1, player1spr, 0, 0, 11, player1spr-&gt;curframe);
  }
  destroy_bitmap(temp1);
  </code></pre>
  
  <p>Errrors like this:</p>
  
  <pre><code>Exception thrown at 0x0F81B605 (allegro-4.4.2-monolith-md.dll) in Assignment2 v2.exe: 0xC0000005: Access violation reading location 0x00000010.
  </code></pre>
  
  <p>I expect my sprite variables to stay the same but they change.</p>