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

Author Topic: Invalid pointer error when setting fonts  (Read 2887 times)

0 Members and 1 Guest are viewing this topic.

codecodecode

  • Newbie
  • *
  • Posts: 26
    • View Profile
Invalid pointer error when setting fonts
« on: March 30, 2017, 11:24:14 pm »
I use the following system to manage drawing text:
// header
        std::map<std::string, sf::Font> fonts;
        std::map<std::string, bool> fontsdbg;

//where text drawing takes place
                fontData * fd = (fontData *)drawnShape->getPropertyByName("font");
                if (fd==nullptr)
                    break;
                if (fd->getData().size()<5)
                    break;

                std::string fontpath = fd->getData();

                if (fonts.find(fontpath)==fonts.end())
                    {
                        fonts[fontpath] = sf::Font();
                        fontsdbg[fontpath]=fonts[fontpath].loadFromFile(fontpath);
                        debug="success! "+fontpath;
                    }
                else if(fontsdbg[fontpath])
                    {
                        debug=std::to_string(fonts.size())+ ">"+fontpath+"< is loaded properly";
                        sf::Text txt; //break; // it doesn't crash if this break statement is uncommented
                        txt.setFont(fonts[fontpath]); //it crashes when it reaches this command.
....
 
Here's the error I get:
Quote
*** Error in `....`: double free or corruption (out): 0x08c77200 ***
Aborted

Process returned 134 (0x86)
Other times I get this error:

Quote
*** Error in `....`:  free(): invalid pointer
Aborted

Process returned 134 (0x86)

Note that analogous code works just fine for setting textures onto sprites and drawing them. Therefore I suspect it might have more to do with C++ than SFML, but I'm asking here just in case.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10991
    • View Profile
    • development blog
    • Email
Re: Invalid pointer error when setting fonts
« Reply #1 on: March 30, 2017, 11:50:13 pm »
You're dealing with raw pointers and C-casting data around, so I'd say, your code has a higher chance of running into a crash than SFML, which is running fine for a few hundred people.

The given code is however not enough to help you with what the issue might be.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

codecodecode

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Invalid pointer error when setting fonts
« Reply #2 on: April 01, 2017, 12:23:26 pm »
Reduced the code to the following:
                    sf::Font f2;
                    if (!f2.loadFromFile("DejaVuSans.ttf"))
                        {
                            condition=false;
                            owner->setdbgstr("error");
                        }
                    else
                        {
                            owner->setdbgstr("no error");
                            sf::Text tx;
                            tx.setFont(f2);
                            tx.setString("i run");
                            draw(tx);
                        }
 
Still got the crashes. Then I tried to get individual glyphs from the texture, but at this line:
sf::Glyph glyph = f2.getGlyph(codePoint, characterSize, bold);
I got the following error:
Quote
undefined reference to `sf::Font::getGlyph(unsigned int, unsigned int, bool, float) const
The function seems to not be implemented.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10991
    • View Profile
    • development blog
    • Email
Invalid pointer error when setting fonts
« Reply #3 on: April 01, 2017, 12:55:12 pm »
The forth parameter (float) for getGlyph, was only added in SFML 2.4. So you're probably using an older version.
« Last Edit: April 01, 2017, 07:07:58 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

codecodecode

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Invalid pointer error when setting fonts
« Reply #4 on: April 01, 2017, 07:00:57 pm »
Hmm. Deleted all links to external headers and it still compiled. It gets them from somewhere else and I have no idea where from. Only deleting links to internal headers or sfml object files gives me errors. Maybe a quirk of the IDE, but the global include section is also empty.

Rosme

  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Re: Invalid pointer error when setting fonts
« Reply #5 on: April 03, 2017, 05:59:38 pm »
Headers is not the issue here. It's the library. You probably have an older version still installed that it still links to.
GitHub
Code Concept
Twitter
Rosme on IRC/Discord

 

anything