I am using SFML to create a simple tower defense game. I got it working, and now I want to get into some more complicated game logic. So I wanted to organize the code a bit before doing that. I was running most everything out of the main with only 2 other classes. So to organize I decided to make a game class.
When I was using the main, I was loading textures just fine. This is how I did it in the main.
//main
sf::Texture* texture1 = new sf::Texture;
texture1 ->loadFromFile("filelocation");
After I did this, and dereferenced it when using it, it was working fine.
However, when I created a class with
sf::Texture* texture1;
as a public member variable, and initializing it in the constructor like this, it doesn't work.
//Game constructor.
texture1 = new sf::Texture;
texture1->loadFromFile("filelocation");
I've also tried using
texture1->create(50,50);
but that didn't do anything.
The error I am getting is
0xC0000005: Access violation writing location 0x0000000000000008.
I had this same error when I was incorrectly using pointers in the main, but now I don't know what is doing wrong.
The error means that it is trying to access a null pointer, but I declared the pointer with the Texture constructor, so I don't know what the problem is.
I am calling the Game constructor in the main like this:
//main
Game game = Game();
Any help would be greatly appreciated, Thanks!