Hello guys,
I have a problem with my sf::Sprite in my own class(CEditbox).
I figured out that as soon as i use any command with my variable 'text' of sf::Text the sprite's sf::Drawable and sf::Transformable property '__vfptr' turns 'unable to read memory'. Every other property remains fine.
Therefore i get the following error, if i try to draw the sprite:
Unhandled exception at 0x0F134CBE (sfml-graphics-d-2.dll) in Editor.exe: 0xC0000005: Access violation reading location 0x00000004.
This is the class, where the editboxes are stored:
class CControls{
public:
CControls(sf::RenderWindow& paWindow, CAssetmanager& paAm);
~CControls(void);
void addEditbox(int paType, sf::Vector2i paPos);
private:
std::vector<std::shared_ptr<CEditbox>> editboxes;
sf::RenderWindow& window;
CAssetmanager& am;
};
CControls::CControls(sf::RenderWindow& paWindow, CAssetmanager& paAm) : window(paWindow), am(paAm) {
}
CControls::~CControls(void){
}
void CControls::addEditbox(int paType, sf::Vector2i paPos){
editboxes.push_back(std::shared_ptr<CEditbox>(new CEditbox(paType, paPos, window, am)));
}
This is the class itself:
class CEditbox {
public:
CEditbox(int paType, sf::Vector2i paPos, sf::RenderWindow& paWindow, CAssetmanager& paAm);
~CEditbox(void);
void setText(std::string paText);
private:
sf::Font& font;
sf::Text text;
sf::RenderWindow& window;
CAssetmanager& am;
};
CEditbox::CEditbox(int paType, sf::Vector2i paPos, sf::RenderWindow& paWindow, CAssetmanager& paAm) : window(paWindow), font(paAm.getFont()), am(paAm),line(sf::RectangleShape(sf::Vector2f(2, 20))){
switch(paType){//templates for editboxes
case 1:
sprite.setTexture(paAm.getTexture(2));
sprite.setTextureRect(paAm.getTextureRect(209));
text.setFont(font);
text.setCharacterSize(20);
text.setPosition(paPos.x + 5, paPos.y + 5);
text.setColor(sf::Color::Black);
break;
}
text.setString(sf::String(""));
sprite.setPosition(pos.x, pos.y);
size = sf::Vector2i(sprite.getTextureRect().width, sprite.getTextureRect().height);
}
CEditbox::~CEditbox(void){
}
void CEditbox::setText(std::string paText){
text.setString(paText);
}
I showed only the most important parts of the code (to my mind). If i completly comment all 'text' commands out, everything works fine.
What could be the problem?
Im using MVS2012 and the dynamic version of sfml.
edit:completly modified