A question about the use of TGUI in a C++11 project

Started by gupas, 26 July 2013, 20:38:14

gupas

Hello,

I tried TGUI and it is an awesome lib (really great work texus).

I compiled it from the latest git version and it worked great with examples (excepted Slider2d on FullExample but it is a dev version, no?).
Then I made some test on one of my project and when I closed the window, I had a segmentation fault.
These is call stack if you want (main.cpp:103 is the end of the main: return 0;):

#0 00454DC8 std::basic_string<unsigned int, std::char_traits<unsigned int>, std::allocator<unsigned int> >::_M_data(this=0xbaadf025) (c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/basic_string.h:290)
#1 00454DB7 std::basic_string<unsigned int, std::char_traits<unsigned int>, std::allocator<unsigned int> >::_M_rep(this=0xbaadf025) (c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/basic_string.h:298)
#2 004783D2 std::basic_string<unsigned int, std::char_traits<unsigned int>, std::allocator<unsigned int> >::~basic_string(this=0xbaadf025, __in_chrg=<optimized out>) (c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/basic_string.h:536)
#3 0044D26B sf::String::~String(this=0xbaadf025, __in_chrg=<optimized out>) (../external/include/SFML/System/String.hpp:43)
#4 0044DDC6 tgui::Callback::~Callback(this=0xbaadf00d, __in_chrg=<optimized out>) (../external/include/TGUI/Callback.hpp:46)
#5 004C4962 std::_Destroy<tgui::Callback>(__pointer=0xbaadf00d) (c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/stl_construct.h:95)
#6 00487F43 std::_Destroy_aux<false>::__destroy<tgui::Callback*>(__first=0xbaadf00d, __last=0xbaadf20d) (c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/stl_construct.h:105)
#7 004C4B04 std::_Destroy<tgui::Callback*>(__first=0xbaadf00d, __last=0xbaadf20d) (c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/stl_construct.h:128)
#8 004C4B20 std::_Destroy<tgui::Callback*, tgui::Callback>(__first=0xbaadf00d, __last=0xbaadf20d) (c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/stl_construct.h:155)
#9 004B02A2 std::deque<tgui::Callback, std::allocator<tgui::Callback> >::_M_destroy_data_aux(this=0x28fa6c, __first=..., __last=...) (c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/deque.tcc:804)
#10 004B0228 std::deque<tgui::Callback, std::allocator<tgui::Callback> >::_M_destroy_data(this=0x28fa6c, __first=..., __last=...) (c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/stl_deque.h:1825)
#11 004B0407 std::deque<tgui::Callback, std::allocator<tgui::Callback> >::~deque(this=0x28fa6c, __in_chrg=<optimized out>) (c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/stl_deque.h:907)
#12 004B0437 std::queue<tgui::Callback, std::deque<tgui::Callback, std::allocator<tgui::Callback> > >::~queue(this=0x28fa6c, __in_chrg=<optimized out>) (c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/stl_queue.h:92)
#13 0044DD88 tgui::Gui::~Gui(this=0x28fa08, __in_chrg=<optimized out>) (../external/include/TGUI/Gui.hpp:37)
#14 0040BAC8 main(argc=1, argv=0xcc34a8) (C:\Users\...\PROJECT\src\main.cpp:103)


I probably spent a couple of hours to find that it was because my project is a c++11 one while I built TGUI "normally".
I also spend some times to find how I can build TGUI using c++11. (If it can help someone, in cmake (using cmake gui), check "Advanced" and add "-std=c++11" (or any other option) to CMAKE_CXX_FLAGS).

However I still have a question:
SFML 2.0 packages are not built using c++11 (normally) but I use them without any problem in my c++11 project. So why, for TGUI, I need to build using c++11?


EDIT: Now I also remember that I had some problems with the font file: "Failed to add a new character to the font: the maximum texture size has been reached".
I tried to replace the font by an other version of DejaVuSans that I use in one project and it worked... Personally I don't understand why... I uploaded the working font if you are interested. The file is too big... Can you increase the max size, please? (compressed size is around 300KB)

texus

QuoteI compiled it from the latest git version and it worked great with examples (excepted Slider2d on FullExample but it is a dev version, no?).
What's wrong with Slider2d?
There was a problem with MenuBar because of a recent changed but thats fixed now.
It is a development version, but usually eveything works. From time to time I just forget to update the example code or the form builder.

QuoteSFML 2.0 packages are not built using c++11 (normally) but I use them without any problem in my c++11 project. So why, for TGUI, I need to build using c++11?
I'm actually surprised that it wouldn't work when tgui isn't compiled with c++11. I'll look into this.

QuoteEDIT: Now I also remember that I had some problems with the font file: "Failed to add a new character to the font: the maximum texture size has been reached".
I tried to replace the font by an other version of DejaVuSans that I use in one project and it worked... Personally I don't understand why... I uploaded the working font if you are interested. The file is too big... Can you increase the max size, please? (compressed size is around 300KB)
I can't allow bigger files to be uploaded. I could, but I only have very limited disk space on my host. And I wouldn't even know where I would have to change the upload limit. Although a few extra KBs won't hurt, I prefer to have as much data as possible on external servers. You could perhaps temporary put it on dropbox or something similar.

Is the issue really with tgui anyway? Try loading it with an sf::Font and sf::Text and see if you get the same error. If you do then its just the font file that's corrupted.

texus

I looked at the c++11 issue and it seems like it has something to do with boost. If I uncomment everything related to boost (basically the whole callback system) then the crash no longer occurs.

I only used boost to support older compilers as long as possible, so once I start using c++11 in my own code this issue will go away.

I was already considering whether c++11 would be for v0.6 or for v0.7, but this issue increases the chance that I will replace boost with c++11 in v0.6. Once I make the change, the "-std=c++11" option will be automatically set in cmake and you will have to set it in codeblocks in order to use tgui.

For now you'll just have to do with manually putting that option into cmake.

gupas

QuoteWhat's wrong with Slider2d?
There was a problem with MenuBar because of a recent changed but thats fixed now.
It is a development version, but usually eveything works. From time to time I just forget to update the example code or the form builder.

I was not sure if Slider2d was an old version (for compatibility) of Slider or not (that's why I said it is a dev version). So for Slider2d in FullExample, the compiler said:
obj\Debug\FullExample.o: In function `main':
FullExample.cpp:131: undefined reference to `tgui::Slider2d::load(std::string const&)'
obj\Debug\FullExample.o: In function `ZN4tgui15SharedWidgetPtrINS_8Slider2dEEC1ERNS_9ContainerERKN2sf6StringE':
TGUI\examples\FullExample/../../build/include/TGUI/SharedWidgetPtr.hpp:69: undefined reference to `tgui::Slider2d::Slider2d()'
collect2.exe: error: ld returned 1 exit status


[EDIT]And for MenuBar I used menu->setTextSize(18);[/EDIT]


Quote
QuoteEDIT: Now I also remember that I had some problems with the font file: "Failed to add a new character to the font: the maximum texture size has been reached".
I tried to replace the font by an other version of DejaVuSans that I use in one project and it worked... Personally I don't understand why... I uploaded the working font if you are interested. The file is too big... Can you increase the max size, please? (compressed size is around 300KB)
I can't allow bigger files to be uploaded. I could, but I only have very limited disk space on my host. And I wouldn't even know where I would have to change the upload limit. Although a few extra KBs won't hurt, I prefer to have as much data as possible on external servers. You could perhaps temporary put it on dropbox or something similar.

Is the issue really with tgui anyway? Try loading it with an sf::Font and sf::Text and see if you get the same error. If you do then its just the font file that's corrupted.
I didn't think to upload it to another place... So here: https://ubuntuone.com/55Y0cf9MR4rbf5xu2S851F The file have some Bytes of differences with your version.
The error message comes from SFML. I tried to reproduce the bug, but now it works. It's a bit strange. Perhaps, it was related to the C++11...


Quote
I only used boost to support older compilers as long as possible, so once I start using c++11 in my own code this issue will go away.
QuoteFor now you'll just have to do with manually putting that option into cmake.
Ok, I already done this. But until you start using C++11, you may notice this in the installation tutorials?

texus

I just compared the contents of the .a and .lib files on windows with the .so files from linux, and it seems that Slider2d is not in the libraries on windows. The part that has to do with SharedWidgetPtr is in there, but the Slider2d class itself is absend. The strange thing is, that on linux everything is ok. So its not like I forgot to add Slider2d to my cmake script because then it wouldn't be in the .so file either. So I'm not sure where I will have to look to fix this issue.

A warning for the c++11 has been added to the tutorial.

gupas

For cmake, I really don't know. I can help you, sorry.

netrick

It's strange.

On my linux system, I compile SFML + TGUI without C++11 enabled.
On my project I use C++11 and everything works great.

EDIT:

Sorry, I have a soul of archaeologist lol :D

texus

This is an old topic. What is said here isn't relevant anymore because TGUI now uses C++11.

QuoteOn my linux system, I compile SFML + TGUI without C++11 enabled.
That isn't supposed to work, unless the compiler has -std=c++11 by default.
But keep in mind that I set this option in my cmake script myself, so unless you change the flags, you will be compiling tgui with c++11.