SFML community forums
Help => Graphics => Topic started by: AurelienFT on March 13, 2019, 07:21:29 pm
-
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 :
#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 :
==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 ?
-
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...
-
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
-
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 (https://fonts2u.com/brushcrazy-demo-regular.font) you referenced.
-
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 ?
-
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? ;)
-
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).
-
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.