16
Graphics / Texture Manager, how to make sprites take pointers?
« on: June 07, 2017, 08:55:24 pm »
Hey everyone,
What I try to do:
TextureManager.h holds a static pointer to a texture. I want my Sprites, which are basically stored in the class Pic, which are stored in the class Node, which are stored in a vector<Node> to use the texture, to which the texture pointer of my TextureManager points to. For some mysterious reasons its not working. Here are the relevant parts of the code:
Is there any way to fix this in an easy way? I know I could use some additional classes and something like the resource manager tutorial, but i would like to keep it really simple and readable.
Error Code is: Exception thrown at 0x00007FFA4C7B6F80 (sfml-graphics-2.dll) in Shattering.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
What I try to do:
TextureManager.h holds a static pointer to a texture. I want my Sprites, which are basically stored in the class Pic, which are stored in the class Node, which are stored in a vector<Node> to use the texture, to which the texture pointer of my TextureManager points to. For some mysterious reasons its not working. Here are the relevant parts of the code:
//TEXTUREMANAGER.H
#include <SFML/Graphics.hpp>
//Textures
static sf::Texture* nodeTexture;
static void loadTextureSet(int i) { //called from main method, works properly, can check the correct size after loading
nodeTexture = new sf::Texture();
nodeTexture->loadFromFile("Graphics/emptyNode.png");
}
//PIC.H
#pragma once
#include <SFML/Graphics.hpp>
class Pic
{
public:
Pic( int pathID );
~Pic();
sf::Texture* texture;
sf::Sprite sprite;
};
//PIC.CPP
#include "Pic.h"
#include <SFML/Graphics.hpp>
#include "TextureManager.h"
Pic::Pic(int pathID)
{
switch (pathID) {
case 0:
texture = nodeTexture;
break;
}
//can successfully call the size of texture until here
sprite.setTexture(*(texture)); //<- ERROR HERE
//error will occur at the line above this one, cant give out any std::cout here.
}
#include <SFML/Graphics.hpp>
//Textures
static sf::Texture* nodeTexture;
static void loadTextureSet(int i) { //called from main method, works properly, can check the correct size after loading
nodeTexture = new sf::Texture();
nodeTexture->loadFromFile("Graphics/emptyNode.png");
}
//PIC.H
#pragma once
#include <SFML/Graphics.hpp>
class Pic
{
public:
Pic( int pathID );
~Pic();
sf::Texture* texture;
sf::Sprite sprite;
};
//PIC.CPP
#include "Pic.h"
#include <SFML/Graphics.hpp>
#include "TextureManager.h"
Pic::Pic(int pathID)
{
switch (pathID) {
case 0:
texture = nodeTexture;
break;
}
//can successfully call the size of texture until here
sprite.setTexture(*(texture)); //<- ERROR HERE
//error will occur at the line above this one, cant give out any std::cout here.
}
Is there any way to fix this in an easy way? I know I could use some additional classes and something like the resource manager tutorial, but i would like to keep it really simple and readable.
Error Code is: Exception thrown at 0x00007FFA4C7B6F80 (sfml-graphics-2.dll) in Shattering.exe: 0xC0000005: Access violation reading location 0x0000000000000000.