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

Author Topic: sf::Font::getTexture(unsigned int) const() ?  (Read 3922 times)

0 Members and 2 Guests are viewing this topic.

Mal1

  • Newbie
  • *
  • Posts: 18
    • View Profile
sf::Font::getTexture(unsigned int) const() ?
« on: May 15, 2013, 07:36:27 pm »
So, I'm working on a little project, the thing is, I have to auto-format sf::Text objects in a really simple matter
You're given a sf::FloatRect, all data needed is counted out, then each object depending from it's width and height is moved to it's position and so on

The problem I have is, when I'm done toying around with a vector of sf::Text * (objects created by new, all have the same font), and then trying to draw them to a sf::RenderWindow it throws out an error in the debugger as following

#0 669830B1   sf::Font::getTexture(unsigned int) const() (dir\sfml-graphics-2.dll:??)
#1 046305C8   ?? () (??:??)
#2 00000001   ?? () (??:??)
#3 04699FE8   ?? () (??:??)


Using one of the 'nightly' SFML 2.0 for MinGW32
Any ideas what could I do wrong? I'm kinda stuck...
The line causing all this crash is just a simple Window->draw( something ), so it's not really that worth showing, unless you think it is

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: sf::Font::getTexture(unsigned int) const() ?
« Reply #1 on: May 16, 2013, 01:55:45 am »
It seems like your font is not properly allocated by the time it needs to be used to render. On the other hand, it may also be a problem with the character size of the sf::Text instances. Not sure which you re doing wrong :)

Mal1

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: sf::Font::getTexture(unsigned int) const() ?
« Reply #2 on: May 16, 2013, 08:19:05 am »
Any idea how could I check which one is wrong?
I'm already using a if( !loadingfont ) code to check if the font was actually loaded, and create sf::Text instances with default constructor and then setting string and character size...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Laurent Gomila - SFML developer

Mal1

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: sf::Font::getTexture(unsigned int) const() ?
« Reply #4 on: May 16, 2013, 07:16:08 pm »
I did actually read that thread, the thing is, I don't think I could provide an example without changing about 200 lines of code.
I just commented out few lines, ran a debugger again, and had a crash with sf::Font::cleanup()
Uh, I could change it a little and give someone a link to the files from dropbox, if anyone is willing to take it for a test drive, in the meantime I'm going to change the font
« Last Edit: May 16, 2013, 08:29:47 pm by Mal1 »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf::Font::getTexture(unsigned int) const() ?
« Reply #5 on: May 16, 2013, 08:00:31 pm »
I did actually read that thread, the thing is, I don't think I could provide an example without changing about 200 lines of code.
The problem is, if you are not able to reduce the code, how should we do it? We don't know your project and would have to waste a lot of timing trying to understand it, although the biggest part of it is not relevant for the error.

Also, there will probably not be many people that download whole project files and test them, for the same reason. You should really use a debugger and try to find the error yourself, or come up with a small example. But first make sure your project is setup correctly, and that you link the right configuration, and so on.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Font::getTexture(unsigned int) const() ?
« Reply #6 on: May 16, 2013, 08:27:12 pm »
Quote
I don't think I could provide an example without changing about 200 lines of code.
Don't try to reduce your original code, write a new one. You have a problem with texts and fonts, let's start with that. Write a minimal SFML app that loads a font and draws a text that uses it. If it doesn't crash, add code step by step, to make it closer to your original code, until it crashes again.

The first code is very important: if it crashes then it's most likely an environment or configuration issue (or a SFML bug). If not, you now know that you're doing something wrong in your code, and doing as I explain above will lead you to the cause of the crash.
Laurent Gomila - SFML developer

Mal1

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: sf::Font::getTexture(unsigned int) const() ?
« Reply #7 on: May 16, 2013, 08:29:16 pm »
Okay, thanks guys, I guess I'll just have to redo some code then

/edit:
So, I managed to change it around, now it's...
well, it's not crashing, that's for sure.
I need to check around to see what isn't working properly though
« Last Edit: May 16, 2013, 08:58:50 pm by Mal1 »

Mal1

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: sf::Font::getTexture(unsigned int) const() ?
« Reply #8 on: May 18, 2013, 11:37:59 pm »
Woot, it's working, after sooooome rewriting and changing only 2 lines of code
But, I managed to find an extra bug in the algorithm, so that's something!
Question, how do I get a space in SFML? I want it to be properly sized, and for now I can only do stuff with pixels themselves...

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: sf::Font::getTexture(unsigned int) const() ?
« Reply #9 on: May 19, 2013, 02:31:23 am »
You get the glyph of space and get its advance. Something like font.getGlyph(' ').advance .. Im rusty tho :D

Mal1

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: sf::Font::getTexture(unsigned int) const() ?
« Reply #10 on: May 19, 2013, 12:14:48 pm »
Thanks, that did the trick ^^
Thanks for all the help guys