1
Graphics / Problems with passing sf::Texture* as a parameter
« on: July 28, 2014, 08:12:15 pm »
I'm pretty new to programming so apologies if this is more due to my inability to understand pointers rather than the library itself.
Anyway, my problem involves trying to pass sf::Texture* (I'm guessing the memory address of a texture) through a constructor of another class so that it can use that texture as its sprite. I feel I'm passing addresses around properly because I have no trouble passing a variable of type sf::Texture*, that is public, around different classes. I get the error "Access violation reading location 0xffffffffffffffff"
As for the bits of my code that are relevant (I'll post more if that's needed to fix the problem):
The logic of my game is simple so I feel this is my only roadblock, so extra advanced thanks to anyone who knows the issue
Anyway, my problem involves trying to pass sf::Texture* (I'm guessing the memory address of a texture) through a constructor of another class so that it can use that texture as its sprite. I feel I'm passing addresses around properly because I have no trouble passing a variable of type sf::Texture*, that is public, around different classes. I get the error "Access violation reading location 0xffffffffffffffff"
As for the bits of my code that are relevant (I'll post more if that's needed to fix the problem):
//in PuzzleRoom.cpp
roomObjects[i][j] = new RoomObject(objManager->getTextureLink(0), objManager->getObjName(0), i, j);
test = objManager->getTextureLink(0); //test variable accessed from other classes
//in RoomObject.cpp
RoomObject::RoomObject(sf::Texture* sprLoc, std::string name, int xLocation, int yLocation)
{
spriteLoc = sprLoc;
objName = name;
xLoc = xLocation;
yLoc = yLocation;
thisShape.setFillColor(sf::Color::White);
thisShape.setPosition(xLoc * 32, yLoc * 32);
thisShape.setSize(sf::Vector2f(32, 32));
thisShape.setTexture(spriteLoc);
}
roomObjects[i][j] = new RoomObject(objManager->getTextureLink(0), objManager->getObjName(0), i, j);
test = objManager->getTextureLink(0); //test variable accessed from other classes
//in RoomObject.cpp
RoomObject::RoomObject(sf::Texture* sprLoc, std::string name, int xLocation, int yLocation)
{
spriteLoc = sprLoc;
objName = name;
xLoc = xLocation;
yLoc = yLocation;
thisShape.setFillColor(sf::Color::White);
thisShape.setPosition(xLoc * 32, yLoc * 32);
thisShape.setSize(sf::Vector2f(32, 32));
thisShape.setTexture(spriteLoc);
}
The logic of my game is simple so I feel this is my only roadblock, so extra advanced thanks to anyone who knows the issue