Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Unhandled Exception when trying to draw a Text object from within a Drawable  (Read 1942 times)

0 Members and 1 Guest are viewing this topic.

beamer159

  • Newbie
  • *
  • Posts: 3
    • View Profile
I am receiving an unhandled exception error when trying to draw a Text object. Here is the error message:

Quote
Unhandled exception at 0x59085815 (sfml-graphics-2.dll) in Program.exe: 0xC0000005: Access violation reading location 0x3F800058.

The thing is, I am telling main to draw a Drawable object (InputBox), which is telling another Drawable object (Button) to draw the Text. If I replace the Text object with another Drawable, such as a CircleShape, the program works. Also, if I draw the Button in main directly, it works as well. Here is my code:

My main Program
int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
        InputBox inputBox;
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }
        window.clear(sf::Color::Black);
        window.draw(inputBox);
        window.display();
    }

    return 0;
}

InputBox class
class InputBox : public sf::Transformable, public sf::Drawable
{
public:
        InputBox()
        {
                button = Button();
        }
        virtual void draw(sf::RenderTarget &target, sf::RenderStates states) const
        {
                states.transform *= getTransform();
                target.draw(button, states);
        }
private:
        Button button;
};

Button class
class Button : public sf::Transformable, public sf::Drawable
{
public:
        Button()
        {
                font.loadFromFile("arial.ttf");
                text.setFont(font);
                text.setString("Button");
        }
        virtual void draw(sf::RenderTarget &target, sf::RenderStates states) const
        {
                states.transform *= getTransform();
                target.draw(text, states);
        }
private:
        sf::Font font;
        sf::Text text;
};
« Last Edit: May 14, 2015, 12:15:40 am by beamer159 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
Are you using x64 libs with an x86 application?
Where the DLLs created with the same compiler you're using?
Are you mixing debug and release modes?
Are you mixing SFML version or using old header files?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

beamer159

  • Newbie
  • *
  • Posts: 3
    • View Profile
I am using x86 libs.
I am using VS 2012, and I downloaded the SFML 2.3 package for VS 2012.
I am only using debug mode for the time being.
I don't think I am using old headers. Only those that came with the SFML 2.3 package for VS 2012.

Edit: I just tested this code on another computer with a different version of Visual Studio, and I got the same error. This makes me think the problem is with my code somewhere.
« Last Edit: May 14, 2015, 02:13:41 am by beamer159 »

ratzlaff

  • Newbie
  • *
  • Posts: 33
    • View Profile
    InputBox()
    {
//        button = Button();
    }
 

Try commenting out that line

beamer159

  • Newbie
  • *
  • Posts: 3
    • View Profile
That fixed my issue. Thank you.

 

anything