5
« on: November 23, 2015, 07:25:17 pm »
I didn't even fully understand what the problem is. It was fixed when I commented out the texture and sprite declaration, but I need those for what I am using it for. The code I used was:
Main:
enemy enemies[4];
int main(){
for (int a = 0; a < enemyListL; a++){
enemies[a].name = "dead";
if (!enemies[a].texture.create(32, 32)){}
}
enemies[0].sprite.setPosition(50, 50);
generateEnemy(enemies, "link", 15);
}
Class:
#include <SFML/Graphics.hpp>
using namespace sf;
const int enemyListL = 5;
string enemiesNames[enemyListL] = { "link", "wyrm", "armored wyrm", "glitching wyrm", "evil guard" };
//health, pAttack, aAttack, pDefense, aDefense, speed, luck
int enemyBaseStat[7][enemyListL] = { 5, 5, 5, 5, 5, 5, 5};
class enemy{
public:
string name;
int health;
int level;
int pAtk;
int aAtk;
int pDef;
int aDef;
int speed;
int luck;
Texture texture;
Sprite sprite;
enemy(){ //This is the line it points to with the error
}
};
int takeDamageDisk(Disks disk, enemy enemy1){
srand(time(NULL));
return ((disk.damage * 2) / (enemy1.aDef)) * ((rand() % 15) + 91) / 100;
}
void generateEnemy(enemy enemiesT[4], string name, int level){
for (int a = 0; a < 4; a++){
if (enemiesT[a].name == "dead"){
for (int b = 0; b < enemyListL; b++){
if (name == enemiesNames){
enemiesT[a].level = level;
srand(time(NULL));
enemiesT[a].health = enemyBaseStat[0] * level + (enemyBaseStat[0] * level * (((rand() % 30) - 15) + 100) / 100);
srand(rand() ^ time(NULL));
enemiesT[a].pAtk = enemyBaseStat[1] * level + (enemyBaseStat[1] * level * (((rand() % 30) - 15) + 100) / 100);
srand(rand() * time(NULL));
enemiesT[a].aAtk = enemyBaseStat[2] * level + (enemyBaseStat[2] * level * (((rand() % 30) - 15) + 100) / 100);
srand(rand() ^ time(NULL));
enemiesT[a].pDef = enemyBaseStat[3] * level + (enemyBaseStat[3] * level * (((rand() % 30) - 15) + 100) / 100);
srand(rand() * time(NULL));
enemiesT[a].aDef = enemyBaseStat[4] * level + (enemyBaseStat[4] * level * (((rand() % 30) - 15) + 100) / 100);
srand(rand() ^ time(NULL));
enemiesT[a].speed = enemyBaseStat[5] * level + (enemyBaseStat[5] * level * (((rand() % 30) - 15) + 100) / 100);
srand(rand() * time(NULL));
enemiesT[a].luck = enemyBaseStat[6] * level + (enemyBaseStat[6] * level * (((rand() % 10) - 5) + 100) / 100);
sf::Image image;
image.loadFromFile("Images\Enemies\\" + name + ".png");
enemiesT[a].texture.update(image);
enemiesT[a].sprite.setTexture(enemiesT[a].texture);
}
}
}
}
}
The window compiles correctly but crashes immediately after launch, before the window can even register.
The error is this:
Unhandled exception at 0x777522D2 (ntdll.dll) in RPGFramework.exe: 0xC0000005: Access violation writing location 0x00000004.