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

Author Topic: sf::Text crashing on draw  (Read 7355 times)

0 Members and 1 Guest are viewing this topic.

vvolfster

  • Newbie
  • *
  • Posts: 11
    • View Profile
sf::Text crashing on draw
« on: July 23, 2014, 06:18:43 am »
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;
}
 
« Last Edit: July 23, 2014, 09:40:08 am by vvolfster »

Strelok

  • Full Member
  • ***
  • Posts: 139
    • View Profile
    • GitHub
Re: sf::Text crashing on draw
« Reply #1 on: July 23, 2014, 06:27:08 am »
If you could be more specific about the error code and write an instance (a simple main)  where the program crashes that'd be great.
« Last Edit: July 23, 2014, 06:31:41 am by Strelok »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::Text crashing on draw
« Reply #2 on: July 24, 2014, 01:54:54 am »
Could you add
std::cout << "fontLoaded == true" << std::endl;
into the if (fontLoaded) { } block and let us know what it says?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: sf::Text crashing on draw
« Reply #3 on: July 24, 2014, 03:17:59 am »
Hapax, just because a font isn't loaded will not cause a segault.

To the OP, make sure you compiled SFML with the same compiler that you are using for your application - and make sure you aren't mixing debug/release libs.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::Text crashing on draw
« Reply #4 on: July 24, 2014, 04:13:23 am »
Hapax, just because a font isn't loaded will not cause a segault.
My bad. I just wanted to know the result of that test  ;D
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

vvolfster

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: sf::Text crashing on draw
« Reply #5 on: July 24, 2014, 11:48:16 am »
Hapax, just because a font isn't loaded will not cause a segault.

To the OP, make sure you compiled SFML with the same compiler that you are using for your application - and make sure you aren't mixing debug/release libs.

You were right! I was being silly and not using the right compiler. I had the wrong kit selected in qt :(
However, it has not helped. it is still crashing on draw() very hard. However the error seems to now be write access violation. I've attached a picture of the debugger.
« Last Edit: July 24, 2014, 12:11:08 pm by vvolfster »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: sf::Text crashing on draw
« Reply #6 on: July 24, 2014, 02:46:30 pm »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

vvolfster

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: sf::Text crashing on draw
« Reply #7 on: July 24, 2014, 04:03:44 pm »
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 :

(click to show/hide)

vvolfster

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: sf::Text crashing on draw
« Reply #8 on: July 27, 2014, 06:09:37 am »
I'm still stuck on this guys. If anyone has any insight or alternatives to draw text on screen, I'd appreciate it. I do believe that I must've messed up cMake somehow even though it threw no errors. I followed the tutorial about it thoroughly so I'm at wits end currently :S

Strelok

  • Full Member
  • ***
  • Posts: 139
    • View Profile
    • GitHub
Re: sf::Text crashing on draw
« Reply #9 on: July 27, 2014, 06:46:06 am »
This is a shot in the dark. Is it possible that even though you now have compiled the libs correctly the debug build still refers to the old ones? Did you have to copy paste DLLs to the debug folder? That's what I'm getting at.

vvolfster

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: sf::Text crashing on draw
« Reply #10 on: July 27, 2014, 08:59:05 am »
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\
« Last Edit: July 27, 2014, 09:20:58 am by vvolfster »

Strelok

  • Full Member
  • ***
  • Posts: 139
    • View Profile
    • GitHub
Re: sf::Text crashing on draw
« Reply #11 on: July 27, 2014, 09:28:10 am »
from this really old post and this really old issue there's a remote chance it's either due to a really old sfml version or (as you've already supposed) a wrong/incomplete linking order. I've never used qt and I've never tried using sfml statically so never take my suggestions as reliable  :P
From the wiki: How do I link SFML statically?
Change the link order accordingly and post the output.
« Last Edit: July 27, 2014, 09:45:01 am by Strelok »

vvolfster

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: sf::Text crashing on draw
« Reply #12 on: July 27, 2014, 09:43:04 am »
OMG! IT LIVETH!

I went back to my older compiled version but gave it the include path of a freshly downloaded copy and it worked. Idk how the include folder originally got messed up  or why it even built other things (besides text) but I won't question my good fortune.

I would still be interested in knowing what the hell just happened though.

Strelok

  • Full Member
  • ***
  • Posts: 139
    • View Profile
    • GitHub
Re: sf::Text crashing on draw
« Reply #13 on: July 27, 2014, 10:00:37 am »
I won't question my good fortune.
This reminds me of something...
  ;D

vvolfster

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: sf::Text crashing on draw
« Reply #14 on: July 27, 2014, 10:58:26 am »
Hahaha, but the bug got crushed this time through the good fortune bestowed upon me by RNGesus.