0xC0DED00D
0xC0DED00D

Reputation: 20348

Access violation writing location 0xaaaaaaaa

This is my current code of the class Score in the Score.h file:-

class Score
{

protected:
long m_Scores;
long m_HighScore;
//private:

public:
Score();
~Score();
void Init();
void Update(float deltaMS);
void Render();
void Release();
void SetScore(long sc){
    m_Scores=sc;
}

long GetScore(){
    return m_Scores;
}
void SetHighScore(long sc){
    m_HighScore=sc;
}

long GetHighScore(){
    return m_HighScore;
}
void AddScore(int add);

};

I am getting the following error whenever I try to access m_Scores in the class itself.

Access violation writing location 0xaaaaaaaa.

The SetScore() method can't be run due to this. I know I am doing something silly, but couldn't figure it out. Can you please help me out.

Upvotes: 0

Views: 909

Answers (2)

Michael Slade
Michael Slade

Reputation: 13877

You are apparently accessing the class through a pointer, and the memory at the pointer's location has the value 0xaaaaaaaa. This looks a lot like a value that uninitialised memory would have.

So I guess you have a Score * variable that you are not filling in with something. You need to do one of

  • change it to Score, and use direct member access (.) instead of pointer indirection (->)
  • initalise the variable with var = new Score(); and later free it with free var;

Upvotes: 2

inkooboo
inkooboo

Reputation: 2944

It happens because your Score object that you try to SetScore() is already outdated, destoryed. Pay attention to its lifetime.

Upvotes: 1

Related Questions