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

Author Topic: sfml text exception  (Read 2146 times)

0 Members and 1 Guest are viewing this topic.

slohobo

  • Newbie
  • *
  • Posts: 5
    • View Profile
sfml text exception
« on: August 12, 2017, 06:52:31 pm »
I am trying to display a Text object and I am receiving an error when I try sending it to the draw function in my sf::RenderWindow object. Bear in mind that I was originally a java programmer so I might be doing something that only works in java (but I doubt it).

The exception looks like (though I doubt it will do any good because it seems like it is sending me the location in the runtime memory the exception is occuring):

Exception thrown at 0x548EAB3F (sfml-graphics-d-2.dll) in Survior.exe: 0xC0000005: Access violation reading location 0xCCCCCD24. occurred

//where exception in relayed
        void TextInteraction::textDisplay() {
                //displays regular text white
                MainWindow::window.draw(*text);
        }
//constructor
        TextInteraction::TextInteraction(RECT box, std::string _text, sf::Font font, int size, float x, float y) : HitBox(box) {
                text = new sf::Text(_text, font, size);
                text->setOrigin(x, y);
                text->setColor(sf::Color::White);
        }

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: sfml text exception
« Reply #1 on: August 12, 2017, 07:31:09 pm »
Your sf::Font object you're passing to the constructor is taking a copy, which no longer exists at the end of the constructor. Make it a const reference and you should be fine.

slohobo

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: sfml text exception
« Reply #2 on: August 12, 2017, 11:08:13 pm »
So I made the constructor require a const reference of my sf::Font object, but I am still receiving the same exception as before mentioned.

        TextInteraction::TextInteraction(RECT box, std::string _text, const sf::Font &font,
                                              int size, float x, float y) : HitBox(box) {
                text = new sf::Text(_text, font, size);
                text->setPosition(x, y);
                text->setOrigin(x, y);
                text->setColor(sf::Color::White);
        }
« Last Edit: August 12, 2017, 11:09:48 pm by slohobo »

slohobo

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: sfml text exception
« Reply #3 on: August 13, 2017, 01:07:27 am »
I was hoping that sfml's classes would copy construct the variables I pass to it (cuz I am a newb), and it actually saves memory by requiring the user to make sure the variables that they send to the object have been saved by the user (not just deleted after scope aka a very java way of programming). I have to leave my safe space of OOP.

[You don't need to read the next sentence]
I don't need to const reference but I might as well just leave it there for good luck because either way it isn't going to do anything either way.
        TextInteraction::TextInteraction(RECT box, const std::string &pText, const sf::Font &_font,
                                          const int &_size, float x, float y) : HitBox(box) {
                content = new std::string(pText);
                font = new sf::Font(_font);
                size = new int(_size);
                text = new sf::Text(*content, *font, *size);
                text->setPosition(x, y);
                text->setOrigin(x, y);
                text->setColor(sf::Color::White);
        }
« Last Edit: August 13, 2017, 01:09:32 am by slohobo »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: sfml text exception
« Reply #4 on: August 13, 2017, 01:32:29 am »
0xC0000005 usually indicates that you're mixing x86 and x64 modes, either by using the wrong runtime DLLs or by using the wrong SFML DLL. Makr sure that you use the runtime libs provided by your compiler.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/