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

Author Topic: Just cannot get sf::Text to draw without crash  (Read 8360 times)

0 Members and 2 Guests are viewing this topic.

ThatOneGuyThatDoesStuff

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Just cannot get sf::Text to draw without crash
« on: August 23, 2020, 10:28:10 pm »
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <ioStream>

int main()
{
    sf::Text testText;
    sf::Font font;
    font.loadFromFile("cour.ttf");
    testText.setFont(font);
    testText.setString("Hello World");
    testText.setPosition(200, 200);
    testText.setCharacterSize(25);
    // Create the main window
    sf::RenderWindow renderWindow(sf::VideoMode(WIDTH, HEIGHT), "SFML window");

        // Start the game loop
    while (renderWindow.isOpen())
    {
        // Process events
        sf::Event event;
        while (renderWindow.pollEvent(event))
        {
            // Close window : exit
            if (event.type == sf::Event::Closed)
                renderWindow.close();
        }

        // Clear screen
        renderWindow.clear();

        // Draw sprites
        renderWindow.draw(testText);

        // Update the window
        renderWindow.display();
    }

    return EXIT_SUCCESS;
}
 

No matter what I do, I cannot get an sf::Text object to draw without the app instantly crashing. Been plagued by this problem for months. I've asked reddit, stack overflow and even here. I'm hoping for better results, because I have no idea what else to do to make it work. I have reinstalled both code::blocks and sfml. I installed sfml and Code::Blocks on a different pc, same problem. I have tried different fonts, same problem. All other SFML features function exactly as they should.

I'm using Code::Blocks v17.12 and SFML v2.5.1

If I comment out
font.setFont
, it will run (though not draw obviously). If I comment out
renderWindow.draw(testText)
it will run without a crash.

If I run debugger I get the info that the problem file is C:\Windows\SysWOW64\ig4icd32.dll. I've tried looking that up, but get nothing related to my problem.

Any help is appreciated. Also, if anyone knows a work around, I would appreciate it.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Just cannot get sf::Text to draw without crash
« Reply #1 on: August 24, 2020, 11:48:07 pm »
If the font fails to load then drawing the text using an invalid font could cause the crash.

You should be testing the return value of "loadFromFile". If it fails, the font should not be used.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

ThatOneGuyThatDoesStuff

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Re: Just cannot get sf::Text to draw without crash
« Reply #2 on: August 25, 2020, 11:17:13 pm »
It doesn't fail. I checked that before, I still get the same issue. The font loads fine (at least according, .loadFromFile will execute with a check in place.

To be sure I changed it to:
 
    if (!font.loadFromFile("cour.ttf")){
        std::cout << "Error: font did not load";
    }

No error is thrown.
« Last Edit: August 25, 2020, 11:28:18 pm by ThatOneGuyThatDoesStuff »

FloweyTF

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Just cannot get sf::Text to draw without crash
« Reply #3 on: August 26, 2020, 10:43:27 pm »
Do you know what causes the error? (Such as invalid pointer, etc)

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: Just cannot get sf::Text to draw without crash
« Reply #4 on: August 27, 2020, 12:17:40 pm »
Try creating the RenderWindow first before you do anything else. It probably initialises OpenGL stuff required by sf::Font.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Just cannot get sf::Text to draw without crash
« Reply #5 on: August 27, 2020, 08:54:47 pm »
If creating the render window solves your problem but want to still load resources before the creation of a window, you can create an sf::Context instead that will do all the initialisation that the window does. It's the first time a context is created that does that OpenGL stuff and render window creates a context internally.

As an aside, I was going to suggest just creating the font before the text but that's more for an error when closing the app.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

ThatOneGuyThatDoesStuff

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Re: Just cannot get sf::Text to draw without crash
« Reply #6 on: August 29, 2020, 10:45:11 pm »
@fallahn, thanks for the suggestion, but the problem remains alive and well and unchanged if I do that. Don't suppose you have another suggestion :'(

@Hapax, I moved the text creation to after the font, still same problem. Getting really frustrated. It's such a stupid problem, but quite unsolveable.

ThatOneGuyThatDoesStuff

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Re: Just cannot get sf::Text to draw without crash
« Reply #7 on: August 29, 2020, 11:28:56 pm »
Do you know what causes the error? (Such as invalid pointer, etc)

I really don't. No information is given.

ThatOneGuyThatDoesStuff

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Re: Just cannot get sf::Text to draw without crash
« Reply #8 on: September 01, 2020, 10:41:35 pm »
Doesn't look like anyone has any solutions. Does anyone know a workaround? Maybe some third party software to make text draw to an sfml window? Or is there a way to strong arm it through SFML's code?

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: Just cannot get sf::Text to draw without crash
« Reply #9 on: September 02, 2020, 12:38:37 am »
All I can suggest is go back to basics. Check your environment. Make sure you don't have more than one or an old version of sfml installed. Check your headers match the installation of the library and haven't been copied from a different installation. Ensure that debug libraries are linked to the debug builds and release libraries are linked to the release build. If all else fails try a different compiler, like clang or msvc. At least that way you should be able to eliminate some possibilities.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Just cannot get sf::Text to draw without crash
« Reply #10 on: September 02, 2020, 01:28:19 am »
Did you try running any of the SFML examples? If I had to guess they will crash too because this is looking like another case of buggy Intel OpenGL driver.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

ThatOneGuyThatDoesStuff

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Re: Just cannot get sf::Text to draw without crash
« Reply #11 on: September 05, 2020, 10:33:31 pm »
All I can suggest is go back to basics. Check your environment. Make sure you don't have more than one or an old version of sfml installed. Check your headers match the installation of the library and haven't been copied from a different installation. Ensure that debug libraries are linked to the debug builds and release libraries are linked to the release build. If all else fails try a different compiler, like clang or msvc. At least that way you should be able to eliminate some possibilities.

I have done all of the above except try a different compiler. I'll try that. But, like I said in the original post, I installed SFML on my laptop AND my desktop. It seems unlikely that I made the same setup mistake twice, spaced quite far apart.

Did you try running any of the SFML examples? If I had to guess they will crash too because this is looking like another case of buggy Intel OpenGL driver.

Yeah, they crash
« Last Edit: September 05, 2020, 10:37:27 pm by ThatOneGuyThatDoesStuff »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Just cannot get sf::Text to draw without crash
« Reply #12 on: September 16, 2020, 07:48:21 am »
Go to the Intel's website and find the latest driver for your integrated graphics chip and install that.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ThatOneGuyThatDoesStuff

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Re: Just cannot get sf::Text to draw without crash
« Reply #13 on: September 17, 2020, 09:45:33 pm »
Go to the Intel's website and find the latest driver for your integrated graphics chip and install that.

I'll try that, but like I said, I also tried it on my new windows 10 PC and get the exact same issue, so I have my doubts it will work. If it does though, you have my eternal gratitude.

 

anything