So I've been following an SFML tutorial but unfortunately, it doesn't seem to be working. The tutorial shows a RenderWindow as a global variable and then accesses it like this:
LevelState.h:
struct LevelStateAssets
{
sf::Texture img_background;
sf::Texture img_player;
sf::Texture img_enemy;
};
extern LevelStateAssets ls_Assets;
class LevelState : public StateBase
{
public:
LevelState();
void Input(sf::Event event);
void Update(void);
void Render(void);
private:
sf::Sprite spr_background;
};
LevelState.cpp:
LevelStateAssets ls_Assets;
LevelState::LevelState()
{
ls_Assets.img_background.loadFromFile("res/images/background.png");
ls_Assets.img_player.loadFromFile("res/images/player.png");
ls_Assets.img_enemy.loadFromFile("res/images/enemy.png");
spr_background.setTexture(ls_Assets.img_background);
spr_background.setPosition(0, 0);
}
/* More unnecessary code in the middle */
void LevelState::Render(void)
{
window.draw(spr_background);
}
But when I do this, I get an error that says: "Unhandled exception at 0x774F3632 (ntdll.dll) in SFMLTutorial.exe: 0xC0000005: Access violation writing location 0x00000004"
If you could help me that would be great! Thanks for your time! :)