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

Author Topic: sf::Text::getLocalBounds causes segmentation fault?(SOLVED)  (Read 8591 times)

0 Members and 2 Guests are viewing this topic.

lumaio

  • Newbie
  • *
  • Posts: 8
    • View Profile
sf::Text::getLocalBounds causes segmentation fault?(SOLVED)
« on: December 31, 2015, 06:16:24 pm »
Calling getLocalBounds on an sf::Text object causes a crash.

minimal example:
#include <iostream>
#include <SFML/Graphics.hpp>

int main()
{
  sf::Font f;
  f.loadFromFile("font.ttf");
  sf::Text t;
  t.setFont(f);
  t.setString("some string");
  t.setCharacterSize(16);
  sf::RenderWindow window(sf::VideoMode(1280, 720), "example", sf::Style::Close);
 
  while (window.isOpen())
  {
    sf::Event event;
    while (window.pollEvent(event))
    {
      if (event.type == sf::Event::Closed)
        window.close();
    }

    sf::FloatRect width = t.getLocalBounds();
    window.clear();

    window.display();

  }
}
 

My OS is Windows 10 Pro 64-bit. As far as I can tell nobody else is having this issue so maybe I'm just not using it correctly?
« Last Edit: January 03, 2016, 04:20:34 pm by lumaio »

Ausche

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: sf::Text::getLocalBounds causes segmentation fault?
« Reply #1 on: December 31, 2015, 08:01:15 pm »
What is the exact error message? This looks right.
Struggling to make a game happen!

lumaio

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: sf::Text::getLocalBounds causes segmentation fault?
« Reply #2 on: December 31, 2015, 08:06:26 pm »
That's the thing, There wasn't an error message. Just the standard windows "whatever.exe has stopped working"

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::Text::getLocalBounds causes segmentation fault?
« Reply #3 on: December 31, 2015, 09:00:40 pm »
minimal example:
The example should also be "complete".
You left out the event code.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

lumaio

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: sf::Text::getLocalBounds causes segmentation fault?
« Reply #4 on: January 01, 2016, 04:52:34 pm »
minimal example:
The example should also be "complete".
You left out the event code.

I don't see why it matters but I added it.
Is this an issue with SFML or my own code? It's driving me nuts.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: sf::Text::getLocalBounds causes segmentation fault?
« Reply #5 on: January 01, 2016, 04:54:55 pm »
I don't see why it matters but I added it.
It matters since if the example is not complete then people can't copy-paste it and compile/run it on their own machine.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf::Text::getLocalBounds causes segmentation fault?
« Reply #6 on: January 01, 2016, 05:01:18 pm »
That's the thing, There wasn't an error message. Just the standard windows "whatever.exe has stopped working"
Run it in the debugger and in Debug mode. Then you get a more meaningful error message and see where exactly it crashes. Once you've done that, provide us with that information.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: sf::Text::getLocalBounds causes segmentation fault?
« Reply #7 on: January 01, 2016, 05:27:10 pm »
Is it crashing in any way with the event loop too?
I'm asking because your "crashing" is normal without the event loop, without an event loop in it your program is literally not responding to windows so that message appears.
Back to C++ gamedev with SFML in May 2023

lumaio

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: sf::Text::getLocalBounds causes segmentation fault?
« Reply #8 on: January 01, 2016, 05:47:14 pm »
That's the thing, There wasn't an error message. Just the standard windows "whatever.exe has stopped working"
Run it in the debugger and in Debug mode. Then you get a more meaningful error message and see where exactly it crashes. Once you've done that, provide us with that information.

Best I can do is GDB because visual studio won't link properly for whatever reason.
(gdb) run
Starting program: Z:\Projects\test\test.exe
[New Thread 5868.0x2030]
[New Thread 5868.0x263c]
[New Thread 5868.0x211c]
[New Thread 5868.0x2a28]
[New Thread 5868.0x1c70]
[New Thread 5868.0x21cc]
[Thread 5868.0x1c70 exited with code 0]
[New Thread 5868.0x2aac]
[Thread 5868.0x2aac exited with code 0]
[New Thread 5868.0x2a80]
[New Thread 5868.0xa10]
[New Thread 5868.0x54c]
[New Thread 5868.0x2674]
[Thread 5868.0x2a80 exited with code 0]
[Thread 5868.0xa10 exited with code 0]
[New Thread 5868.0x1230]
[New Thread 5868.0x26a0]
[New Thread 5868.0x27d0]
font loaded..

Program received signal SIGSEGV, Segmentation fault.
0x0000000068eec64c in sf::Text::ensureGeometryUpdate (this=0x8000) at Z:\Source\SFML\src\SFML\Graphics\Text.cpp:350
350         if (!m_geometryNeedUpdate)

Is it crashing in any way with the event loop too?
I'm asking because your "crashing" is normal without the event loop, without an event loop in it your program is literally not responding to windows so that message appears.

I checked, this is not the case.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::Text::getLocalBounds causes segmentation fault?
« Reply #9 on: January 01, 2016, 06:05:26 pm »
You left out the event code.
I don't see why it matters
without an event loop in it your program is literally not responding to windows so that message appears.
That. That it why it matters  :P

I checked, this is not the case.
Are you saying that it doesn't have a fault when you do have an event loop?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

lumaio

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: sf::Text::getLocalBounds causes segmentation fault?
« Reply #10 on: January 01, 2016, 06:13:43 pm »

I checked, this is not the case.
Are you saying that it doesn't have a fault when you do have an event loop?

It still crashes with an event loop.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf::Text::getLocalBounds causes segmentation fault?
« Reply #11 on: January 01, 2016, 07:16:16 pm »
because visual studio won't link properly for whatever reason.
What does that mean? Again, it would be helpful if you could provide an actual problem description instead of a vague statement. This may indicate a configuration problem, and it's useless to debug SFML when the error is simply linking the wrong binary...

In case of doubt, try to rebuild SFML and link your own version. Make sure that you follow the tutorial steps precisely and don't mix any configurations or compiler/linker flags.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

lumaio

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: sf::Text::getLocalBounds causes segmentation fault?
« Reply #12 on: January 01, 2016, 08:33:03 pm »
Building with visual studio and release libs results in the same crash but using the debug libs works fine.
The same can't be said for mingw though, both release and debug have the same issue.
I'm not sure what info from the visual studio debugger you want me to give you, gdb gave me more info than I got from vs.

lumaio

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: sf::Text::getLocalBounds causes segmentation fault?
« Reply #13 on: January 02, 2016, 06:59:15 pm »
So reading this thread back I wasn't clear at all what my config was which is probably confusing so here;
I'm using mingw 5.1.0 and compiling with clang 3.7.0.
I was able to get the code in the OP to work if I compiled in visual studio with the debug libs.
The crash happens at line 350 in Text.cpp
Code: [Select]
if (!m_geometryNeedUpdate)I noticed that sf::Text::ensureGeometryUpdate is called when rendering as well but it doesn't crash when I do that, only when I try to get the bounds (both getLocalBounds and getGlobalBounds).
« Last Edit: January 02, 2016, 07:01:31 pm by lumaio »

Estivo

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: sf::Text::getLocalBounds causes segmentation fault?
« Reply #14 on: January 03, 2016, 01:07:16 am »
Building with visual studio and release libs results in the same crash but using the debug libs works fine.
The same can't be said for mingw though, both release and debug have the same issue.
I'm not sure what info from the visual studio debugger you want me to give you, gdb gave me more info than I got from vs.

I checked it on Win 10 64 bits with SFML 2.3 32bit and both (debug and realease) and VS 2015 (v140) are working fine.

 

anything