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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - CAExempt

Pages: [1]
1
General / Exception thrown when attempting to run an SFML project
« on: April 17, 2020, 01:50:22 am »
Hi everyone,

I'm a bit of a beginner to SFML (and C++ in general).

I've been having an issue when attempting to run my SFML work:

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

VS 2019 has pointed out that the issue lies on line 4 of my alien.cpp file:
#include "../inc/alien.h"
#include <iostream>

sf::Texture alienTexture; //Exception thrown here (0x7742...)

void alien::defineAlien(sf::Sprite& alienSprite, int alienPosX, int alienPosY) {

       
        if (!alienTexture.loadFromFile("./res/alien.png")) {
                alienTexture.loadFromFile("./res/error.png");
        }

        else {
                alienSprite.setTexture(alienTexture);
                alienSprite.setScale(sf::Vector2f(0.2f, 0.2f));
        }


       
        alienSprite.setOrigin(650.0f / 2, 650.0f / 2);

        alienSprite.setPosition(sf::Vector2f(alienPosX, alienPosY));

}

void alien::moveAlien(sf::Sprite& alienSprite) {
       
        if (distanceMoved == 6)
                changeDir = true;

       
        if (distanceMoved == -6)
                changeDir = false;

        if (changeDir == false) {
                alienSprite.move(20.f, 0.f);
                distanceMoved++;
                descend++;
        }
        else if (changeDir) {
                alienSprite.move(-20.f, 0.f);
                distanceMoved--;
                descend++;
        }

}

void alien::descendAlien(sf::Sprite& alienSprite) {
        if (descend == 12) {
                alienSprite.move(0.f, 50.f);
                descendCount++;
                descend = 0;
        }
}

void alien::checkDescend(player& player) {
        if (descendCount == 4) {
                player.playerHealth = 0;
        }
}
 

For reference: the code compiles when ran, but almost-immediately, the exception is thrown.

I've spent some time googling the issue, and reading an old thread (https://en.sfml-dev.org/forums/index.php?topic=12815.0) about a similar issue that happened to someone else. I've also double checked my property pages in my VS solution to ensure that all the associated SFML libraries are being correctly referenced (I can attach screenshots of the property pages here if you wish).

I would appreciate any help with this.

Thanks.

Pages: [1]
anything