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

Author Topic: sf::Texture getSize() crashes the program  (Read 2123 times)

0 Members and 1 Guest are viewing this topic.

lorence30

  • Full Member
  • ***
  • Posts: 124
    • View Profile
    • Email
sf::Texture getSize() crashes the program
« on: April 12, 2016, 08:57:38 pm »
Hello, i have a problem
my problem gets crashed whenever i get the size of square, even in circle and other shapes

int main()
{
     sf::RectangleShape square(sf::Vector2f(50,50));
     std::cout << square.getTexture()->getSize().x;
}

AlejandroCoria

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
    • alejandrocoria.games
    • Email
Re: sf::Texture getSize() crashes the program
« Reply #1 on: April 12, 2016, 09:47:36 pm »
If you do not set a texture to a Shape, getTexture return nullptr.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: sf::Texture getSize() crashes the program
« Reply #2 on: April 13, 2016, 08:04:27 am »
And nullptr can't be accessed (it points to nothing), thus the crash.

What you actually want to use are local or global bounds.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

lorence30

  • Full Member
  • ***
  • Posts: 124
    • View Profile
    • Email
Re: sf::Texture getSize() crashes the program
« Reply #3 on: April 13, 2016, 10:36:13 pm »
i thought it already has a texture and its size is 50x50
thanks :)

 

anything