I'm using Visual C++ 2010 as my IDE. I'm sorry in advance for the wall of code you're about to see, I just figured I would be as detailed as possible. I'll just cut to the chase with the code, and explain at the bottom.
Game function, which loads the font, declares playText and quitText, and then sets their position and string before going onto the rest of the function.
int mainMenu(sf::RenderWindow *window, CircleWrap mouseCircle)
{
int choice = 0;
sf::Font font;
font.loadFromFile("arial.ttf");
TextWrap playText(font), quitText(font);
playText.play();
quitText.quit();
...
This is the TextWrap class, which inherits sf::Text:
class TextWrap : public sf::Text
{
public:
TextWrap(sf::Font font);
void play(void);
void quit(void);
};
This is where the functions of TextWrap are defined:
TextWrap::TextWrap(sf::Font font)
{
setFont(font);
setCharacterSize(30);
setStyle(sf::Text::Bold);
setColor(sf::Color::White);
}
void TextWrap::play(void)
{
setString("Play!");
setPosition(300, 400);
return;
}
void TextWrap::quit(void)
{
setString("Quit");
setPosition(300, 200);
return;
}
This is the error that I get:
First-chance exception at 0x0120afe3 in mouseAvoider.exe: 0xC0000005: Access violation reading location 0xccccccd0.
Unhandled exception at 0x0120afe3 in mouseAvoider.exe: 0xC0000005: Access violation reading location 0xccccccd0.
The actual error is thrown at the setString line. It doesn't matter whether I do the quit or the play functions first, they both throw the exception. As far as I can tell, I cannot tell why I would get an access violation. When I open the callstack, this is the last call that was made:
> mouseAvoider.exe!std::_Iterator_base12::_Adopt(const std::_Container_base12 * _Parent) Line 146 + 0x6 bytes