EDIT: Added my 3rd post here cause I felt this describes the problem much clearly (as Strelok suggested). In a nutshell, every time I try to draw an sf::Text instance, it crashes the program.
So here is simple main code that always results in a crash for me. All I'm trying to do is to draw sf::Text instance. I see "drawing..." on console but never "finished". I've attached the windows APPCRASH message as well as what Qt Debugger is telling me (that it's a seg fault). Both of them specifically mention the msvcrt.dll so I must not have the right version where the SFML app is running?
EDIT: I used cMake with mingw32 compiler to compile SFML btw. I have now tried manually putting every version of the mscvrt.dll (on my computer) into the .exe's folder and tried running it but to no avail. All of them result in the same crash.
#include <SFML/Graphics.hpp>
#include <SFML/Graphics/Text.hpp>
#include <string>
#include <iostream>
std::string getAppPath()
{
std::string appPath = "E:/TunaBattle/TextTest/Build/";
#ifdef debug
appPath += "debug/";
#else
appPath += "release/";
#endif
return appPath;
}
int main()
{
sf::RenderWindow window(sf::VideoMode(1024,768,32),"sf::Text test");
sf::Font font;
sf::Text text;
bool fontLoaded = font.loadFromFile(getAppPath() + "JOKERMAN.TTF");
if(fontLoaded)
{
text.setFont(font);
text.setString("Argh Matey!");
text.setPosition(30,30);
text.setCharacterSize(30);
}
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
window.close();
}
window.clear(sf::Color::White);
if(fontLoaded)
{
std::cout << "drawing...";
window.draw(text);
std::cout << "finished\n";
}
window.display();
}
return 0;
}
Could you add
std::cout << "fontLoaded == true" << std::endl;
into the if (fontLoaded) { } block and let us know what it says?
Using Qt Creator as the IDE so I couldn't quite follow those steps exactly. I added -verbose and --verbose to compiler and linker flags. Here is the output :
06:59:19: Starting: "C:\Program Files (x86)\CodeBlocks\MinGW\bin\mingw32-make.exe"
C:/Program Files (x86)/CodeBlocks/MinGW/bin/mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory `E:/TunaBattle/TextTest/Build'
g++ -c -pipe -fno-keep-inline-dllexport -O2 -std=c++0x -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_NO_DEBUG -DQT_CORE_LIB -I..\TextTest -I"..\..\SFML\include" -I"DEPENDPATH" -I"+=" -I"..\..\SFML\include" -I"QMAKE_CXXFLAGS" -I"+=" -I"-verbose" -I"-std=c++11" -I"..\..\..\Qt\5.2.1\mingw48_32\include" -I"..\..\..\Qt\5.2.1\mingw48_32\include\QtCore" -I"release" -I"." -I"..\..\..\Qt\5.2.1\mingw48_32\mkspecs\win32-g++" -o release\main.o ..\TextTest\main.cpp
g++ --verbose -Wl,-s -Wl,-subsystem,console -mthreads -o release\TextTest.exe release/main.o -LE:/TunaBattle/SFML/lib -lsfml-audio -lsfml-graphics -lsfml-main -lsfml-network -lsfml-window -lsfml-system -LE:\Qt\5.2.1\mingw48_32\lib -lQt5Core
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=c:/program files (x86)/codeblocks/mingw/bin/../libexec/gcc/mingw32/4.7.1/lto-wrapper.exe
Target: mingw32
Configured with: ../../src/gcc-4.7.1/configure --build=mingw32 --enable-languages=c,c++,ada,fortran,objc,obj-c++ --enable-threads=win32 --enable-libgomp --enable-lto --enable-fully-dynamic-string --enable-libstdcxx-debug --enable-version-specific-runtime-libs --with-gnu-ld --disable-nls --disable-win32-registry --disable-symvers --disable-build-poststage1-with-cxx --disable-werror --prefix=/mingw32tdm --with-local-prefix=/mingw32tdm --enable-cxx-flags='-fno-function-sections -fno-data-sections' --with-pkgversion=tdm-1 --enable-sjlj-exceptions --with-bugurl=http://tdm-gcc.tdragon.net/bugs
Thread model: win32
gcc version 4.7.1 (tdm-1)
COMPILER_PATH=c:/program files (x86)/codeblocks/mingw/bin/../libexec/gcc/mingw32/4.7.1/;c:/program files (x86)/codeblocks/mingw/bin/../libexec/gcc/;c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../../mingw32/bin/
LIBRARY_PATH=c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/;c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/;c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../../mingw32/lib/;c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../
COLLECT_GCC_OPTIONS='-v' '-mthreads' '-o' 'release\TextTest.exe' '-LE:/TunaBattle/SFML/lib' '-LE:\Qt\5.2.1\mingw48_32\lib' '-mtune=i386' '-march=i386'
c:/program files (x86)/codeblocks/mingw/bin/../libexec/gcc/mingw32/4.7.1/collect2.exe -Bdynamic -o release\TextTest.exe c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../crt2.o c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/crtbegin.o -LE:/TunaBattle/SFML/lib -LE:\Qt\5.2.1\mingw48_32\lib -Lc:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1 -Lc:/program files (x86)/codeblocks/mingw/bin/../lib/gcc -Lc:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../../mingw32/lib -Lc:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../.. -s -subsystem console release/main.o -lsfml-audio -lsfml-graphics -lsfml-main -lsfml-network -lsfml-window -lsfml-system -lQt5Core -Bstatic -lstdc++ -Bdynamic -lmingwthrd -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingwthrd -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/crtend.o
mingw32-make[1]: Leaving directory `E:/TunaBattle/TextTest/Build'
06:59:21: The process "C:\Program Files (x86)\CodeBlocks\MinGW\bin\mingw32-make.exe" exited normally.
06:59:21: Elapsed time: 00:03.
I have to copy paste dlls if I wanted to run the executable from explorer but not from Qt creator itself. But just to get rid of the whole dll problem I compiled again, this time with the newer mingw32 4.8 with the static_std libs option. It compiles fine but now I keep getting undefined reference errors when trying to build.
I know it must be the .pro file settings but what am I doing wrong? I read elsewhere on the forums that using static sfml libs tends to stop the sf::Text issues so that's why I decided to do this. Here's my .pro file settings.
Is the order of my libs wrong?
If I just try to use -lsfml-system-s , -lsfml-window-s & -lsfml-graphics-s, this is what I get:
0) Putting graphics before window creates 70+ errors as seen in the attached picture.
1) Doing system, window, graphics gets 34 errors
2) Doing window, system, graphics gets 14 errors
3) Doing window, graphics, system gets 14 errors (same as above)
QT -= gui
TARGET = TextTest
CONFIG += c++11 console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
DEFINES += SFML_STATIC
LIBS += -LE:/TunaBattle/SFMLBUILD3/lib
LIBS += -lsfml-audio-s -lsfml-graphics-s -lsfml-main -lsfml-network-s -lsfml-window-s -lsfml-system-s
INCLUDEPATH += E:\TunaBattle\SFMLBUILD3\include\
DEPENDPATH += E:\TunaBattle\SFMLBUILD3\include\