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

Author Topic: new sf::Text make a lot of memory errors and crash in my code  (Read 1801 times)

0 Members and 1 Guest are viewing this topic.

AurelienFT

  • Newbie
  • *
  • Posts: 4
    • View Profile
Hi,

I have a crash in my main code with new sf::Text. So I try this test to figure out why I have a crash :
Quote
#include <SFML/Graphics/Text.hpp>
#include <iostream>

int main(int ac, char **av)
{
        sf::Font font;
        // Load it from a file
        if (!font.loadFromFile("./BrushcrazyDEMO.otf"))
        {
                std::cerr << "test" << std::endl;
        }
        sf::Text *text = new sf::Text("hello", font, 20);
}

With this simple test I have a lot of memory errors like that :

Quote
==24546== Invalid write of size 8
==24546==    at 0x4E8687C: sf::VertexArray::VertexArray(sf::PrimitiveType, unsigned long) (in /usr/lib/libsfml-graphics.so.2.5.1)
==24546==    by 0x4E8577B: sf::Text::Text(sf::String const&, sf::Font const&, unsigned int) (in /usr/lib/libsfml-graphics.so.2.5.1)
==24546==    by 0x401070: main (main.cpp:12)
==24546==  Address 0x8e6b930 is 0 bytes after a block of size 304 alloc'd
==24546==    at 0x4C2E1CA: operator new(unsigned long) (vg_replace_malloc.c:334)
==24546==    by 0x401053: main (main.cpp:12)

PS: line 12 is the line with sf::Text *.
Someone has an idea ?

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: new sf::Text make a lot of memory errors and crash in my code
« Reply #1 on: March 13, 2019, 08:50:55 pm »
it works for me. have you linked everything correctly?
you could also try rebuilding all the code files.
but the problem is probably in SFML setup...
Visit my game site (and hopefully help funding it? )
Website | IndieDB

AurelienFT

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: new sf::Text make a lot of memory errors and crash in my code
« Reply #2 on: March 14, 2019, 01:12:41 am »
Thanks for reply !

I builded SFML 2.5.1 from source with GCC 7.3.1.

My compilation line is : g++ main.cpp -lsfml-graphics -lsfml-window -lsfml-system -g3
« Last Edit: March 14, 2019, 01:14:22 am by AurelienFT »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: new sf::Text make a lot of memory errors and crash in my code
« Reply #3 on: March 14, 2019, 08:49:47 am »
And who says that those are errors? ;)

Just because valgrind (or whatever tool that is), spits out some text, doesn't mean it's actually an issue.
Compiles and runs fine on my end as well, even tried using the font you referenced.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

AurelienFT

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: new sf::Text make a lot of memory errors and crash in my code
« Reply #4 on: March 14, 2019, 09:46:10 am »
Memory leaks can't be a excepted behavior.

I know that's my SFML, I asked to a friend to test ans it works very nice. If i compile 2.5.1 on my computer with gcc 7.3.1, I just need to copy lib folder on my own lib folder and do the same with include folder ?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: new sf::Text make a lot of memory errors and crash in my code
« Reply #5 on: March 14, 2019, 10:05:24 am »
Your code obviously creates a memory leak, as you never delete the allocated sf::Text.

My point was more, whether you fully understand what the output says (as I do not) or whether you just see some text and want to "fix" it? ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: new sf::Text make a lot of memory errors and crash in my code
« Reply #6 on: March 14, 2019, 10:07:36 am »
Quote
If i compile 2.5.1 on my computer with gcc 7.3.1, I just need to copy lib folder on my own lib folder and do the same with include folder ?
The standard way is to put your install path into the CMAKE_INSTALL_PREFIX variable at configure time, and then run "make install" after compiling the project. Manually copying files is error prone, and rarely the right way to install a library.

Note that you can install SFML wherever you want and tell the compiler/linker where it is with -I and -L options, if it's not a standard path.

So my advice would be to remove all SFML files from your Linux (including any previous version still hanging around), and then make a fresh (and correct) install.

And yes, if your initial problem is really a crash, and not just this valgrind output, then please post details about it (run a debugger).
Laurent Gomila - SFML developer

AurelienFT

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: new sf::Text make a lot of memory errors and crash in my code
« Reply #7 on: March 14, 2019, 10:48:07 am »
Merci Laurent. Thanks Laurent ! <3

I use "make install" and it works like a charm with 5.2.1 version and GCC 7.3.1.

I can finally create the new Fortnite.

 

anything