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

Author Topic: Segfault when deleting object that is holding sf::Text  (Read 2007 times)

0 Members and 1 Guest are viewing this topic.

PeterBeater

  • Newbie
  • *
  • Posts: 3
    • View Profile
Segfault when deleting object that is holding sf::Text
« on: March 16, 2017, 08:23:09 am »
Hey all,

Been searching around but haven't found anything on google for the issue I'm seeing. I have a wrapper around the sf::Text. Whenever the wrapper object gets deleted the program segfaults. The interesting thing is that the segfault only occurs when the sf::Text object's had the font AND the string set. If only one of the two are set, the object is deleted without any issue. Anyone have any thoughts on what I'm doing wrong?

I'm using the SFML v2.1 build taken from the repository on Raspbian.
Stripped down code:
#include <SFML/Graphics/Text.hpp>
#include <SFML/Graphics/Font.hpp>

#include <string>
#include <iostream>
#include <memory>

class TextEntity
{
public:
    TextEntity(sf::Font& font, std::string message)
    {
        text.setFont(font);
        text.setString(message);
    }

    ~TextEntity()
    {
        std::cout << "Deleting TextEntity\n";
    }
private:
    sf::Text text;
};

int main()
{
    sf::Font font;
    font.loadFromFile("fonts/Pacifico.ttf");

    std::shared_ptr<TextEntity> entity(new TextEntity(font, "hello Mommy!"));
    return 0;
}
 

Output:
./bin/sample
Deleting TextEntity
Segmentation fault

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Segfault when deleting object that is holding sf::Text
« Reply #1 on: March 16, 2017, 08:49:15 am »
Can you run the debugger to get more details?
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Segfault when deleting object that is holding sf::Text
« Reply #2 on: March 16, 2017, 09:07:39 am »
Make sure you'r not mixing debug and release mode.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

PeterBeater

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Segfault when deleting object that is holding sf::Text
« Reply #3 on: March 16, 2017, 06:20:35 pm »
@eXpl0it3r I compressed all code to a single file so I don't think it's possible to mix debug and release modes?

@Laurent I'm fairly new to gdb so let me know if there's anything specific I should be providing, but here's some extra information:

Program output:
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".
[New Thread 0x73332410 (LWP 1230)]
[New Thread 0x72b32410 (LWP 1231)]
[New Thread 0x72332410 (LWP 1232)]
[New Thread 0x71b32410 (LWP 1233)]
Deleting TextEntity
Program received signal SIGSEGV, Segmentation fault.
__GI___libc_free (mem=0x41f00000) at malloc.c:2929
2929    malloc.c: No such file or directory.
 

(gdb) bt
#0  __GI___libc_free (mem=0x41f00000) at malloc.c:2929
#1  0x00012384 in __gnu_cxx::new_allocator<sf::Vertex>::deallocate (this=0x241b0, __p=0x41f00000) at /usr/include/c++/4.9/ext/new_allocator.h:110
#2  0x0001233c in std::allocator_traits<std::allocator<sf::Vertex> >::deallocate (__a=..., __p=0x41f00000, __n=4239654912)
    at /usr/include/c++/4.9/bits/alloc_traits.h:383
#3  0x000122c0 in std::_Vector_base<sf::Vertex, std::allocator<sf::Vertex> >::_M_deallocate (this=0x241b0, __p=0x41f00000, __n=4239654912)
    at /usr/include/c++/4.9/bits/stl_vector.h:178
#4  0x000121f4 in std::_Vector_base<sf::Vertex, std::allocator<sf::Vertex> >::~_Vector_base (this=0x241b0, __in_chrg=<optimized out>)
    at /usr/include/c++/4.9/bits/stl_vector.h:160
#5  0x0001214c in std::vector<sf::Vertex, std::allocator<sf::Vertex> >::~vector (this=0x241b0, __in_chrg=<optimized out>) at /usr/include/c++/4.9/bits/stl_vector.h:425
#6  0x00011f30 in sf::VertexArray::~VertexArray (this=0x241ac, __in_chrg=<optimized out>) at /usr/local/include/SFML/Graphics/VertexArray.hpp:45
#7  0x00011fcc in sf::Text::~Text (this=0x240d0, __in_chrg=<optimized out>) at /usr/local/include/SFML/Graphics/Text.hpp:48
#8  0x0001172c in TextEntity::~TextEntity (this=0x240d0, __in_chrg=<optimized out>) at src/Main.cpp:18
#9  0x0001209c in std::_Sp_counted_ptr<TextEntity*, (__gnu_cxx::_Lock_policy)1>::_M_dispose (this=0x29ca70) at /usr/include/c++/4.9/bits/shared_ptr_base.h:373
#10 0x00011a88 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)1>::_M_release (this=0x29ca70) at /usr/include/c++/4.9/bits/shared_ptr_base.h:149
#11 0x00011890 in std::__shared_count<(__gnu_cxx::_Lock_policy)1>::~__shared_count (this=0x7effef4c, __in_chrg=<optimized out>)
    at /usr/include/c++/4.9/bits/shared_ptr_base.h:666
#12 0x00011764 in std::__shared_ptr<TextEntity, (__gnu_cxx::_Lock_policy)1>::~__shared_ptr (this=0x7effef48, __in_chrg=<optimized out>)
    at /usr/include/c++/4.9/bits/shared_ptr_base.h:914
#13 0x00011790 in std::shared_ptr<TextEntity>::~shared_ptr (this=0x7effef48, __in_chrg=<optimized out>) at /usr/include/c++/4.9/bits/shared_ptr.h:93
#14 0x00011434 in main () at src/Main.cpp:30
 

PeterBeater

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Segfault when deleting object that is holding sf::Text
« Reply #4 on: March 17, 2017, 06:18:53 am »
I guess there's a bug in the SFML build in the Raspbian repos? I compiled the latest SFML code from github and built the sample program in my original post with the latest SFML build and it runs without segfault.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Segfault when deleting object that is holding sf::Text
« Reply #5 on: March 17, 2017, 06:35:22 am »
It looks like a standard library mismatch.
Laurent Gomila - SFML developer

 

anything