Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Access violation writing location 0x00000004 in Enemy Constructor  (Read 1927 times)

0 Members and 1 Guest are viewing this topic.

firepro20

  • Newbie
  • *
  • Posts: 22
    • View Profile
I am getting the following error when running the program, violation thrown near default constructor of enemy -

Exception thrown at 0x77C76015 (ntdll.dll) in SFML.exe: 0xC0000005: Access violation writing location 0x00000004.

This is the constructor -

Quote
// Default Constructor
Enemy::Enemy()
{
   //set alive
   mIsAlive = true;

   //set speed
   enemySpeed = 10.f;
   // Load an enemy texture
   if (!mEnemyTexture.loadFromFile("Media/Textures/PixelSpaceships/red_01.png")) {
      // Handle loading error
      std::cout << "Oh No! File not loaded." << std::endl;
   }

   //scale sprite and set texture so we know size
   enemySprite.setTexture(mEnemyTexture);
}

From game.cpp I am calling enemyLoader to instantiate enemy. Array of Enemy is in game.cpp as well

Quote
// Enemy

Enemy alienArray[NUMBER_OF_ALIENS];

Quote
// Loading Enemy

   
   enemy.enemyLoader(NUMBER_OF_ALIENS, alienArray);

What can I provide to help in identifying what is causing the issue?

firepro20

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Access violation writing location 0x00000004 in Enemy Constructor
« Reply #1 on: November 21, 2019, 10:00:25 pm »
The issue was resolved by changing the code structure completely in order to avoid calling private methods from public scope. This can be closed.

 

anything