title: Access violation reading location 0x00000004
body: <p>I have a Class Player like this:</p>
  
  <pre><code>class Player
  {
      public:
      Player();
      ~Player(void);
      Sprite *sprite;
      Sprite *rocket;
  
      void draw(int x, int y, SpaceInvaders *system);
  }
  </code></pre>
  
  <p>and in Player.cpp</p>
  
  <pre><code>void Player::draw(int x, int y, SpaceInvaders *system) {
  
      sprite = system-&gt;createSprite("data/player.bmp");
      sprite-&gt;draw(x, y);
  
  }
  
  Player::~Player(void)
  {
      sprite-&gt;destroy();
      rocket-&gt;destroy();
  }
  </code></pre>
  
  <p>This draw method is called in a while loop in main:</p>
  
  <pre><code>player.draw(int(xPos), 480-32, system);
  </code></pre>
  
  <p>The game runs fine until I X the window. That's when I get "Access violation reading location 0x00000004" on the first line in the Player::draw method.
  I've read that it might be due to passing a null pointer or null reference but I don't know how to fix this. </p>
  
  <p>Would appreciate any help, thanks!</p>