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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - homie

Pages: [1]
1
Graphics / Displaying sf::String from a pointer
« on: May 17, 2010, 07:36:09 pm »
Aww go to hell : C You just came and solved it in a second. Yep, works fine, thanks : P

2
Graphics / Displaying sf::String from a pointer
« on: May 17, 2010, 07:06:43 pm »
Read more carefully.
Quote
It solved the crash that was caused by a GetDefaultFont()

I've moved to the SFML 1.6 as Laurent said, it solved the crash but I got another problem which I described. Shall I attach the files?

//Edit:
Maybe I've just improperly migrated to the new version but how can this be if the default constructor no longer crashes the app?

3
Graphics / Displaying sf::String from a pointer
« on: May 16, 2010, 05:02:33 pm »
It solved the crash that was caused by a GetDefaultFont(), but with this piece of code:
Code: [Select]
CText::CText(void)
{
this->m_string.SetText("Hello");
sf::Font f;
if(!f.LoadFromFile("fonts\\arial.ttf", 50))
{
this->m_string.SetText("Font load failure");
}
else
{
this->m_string.SetText("Font loaded successfully");
this->m_string.SetFont(f);
this->m_string.SetSize(40.f);
}
this->m_string.SetColor(sf::Color(0,0,0));
}
void CText::D(sf::RenderTarget &target)
{
target.Draw(m_string);
}

I'm getting a crash while I'm trying to target.Draw. When I comment out the line
Code: [Select]
this->m_string.SetFont(f);
the crash doesn't occur. I know that the default font is arial but later I want to load other fonts and this one is only for testing purpose. And the code works well when I'm using it structurally:
Code: [Select]
sf::String sfSString;
sf::Font f;
if(!f.LoadFromFile("fonts\\arial.ttf", 50))
{
sfSString.SetText("Font load failure");
}
else
{
sfSString.SetText("Font loaded successfully");
sfSString.SetFont(f);
sfSString.SetSize(40.f);
}


Am I doing something wrong?

4
Graphics / Displaying sf::String from a pointer
« on: May 16, 2010, 01:53:54 am »
Hi there.
First of all I want to admit that I am just a beginner but I think this doesn't excuse me : P

I wanted to make a class that has an sf::String object as a member. As this object created without the font argument crashes the program after closing I came to those two solutions:
1. Initialize the object in an initialization list like that:
Code: [Select]
CText(sf::Font& f) : m_string("Sometext", f, 40.f) {}
but with this solution I have to create additional useless instance of sf::Font before I create a CText object like that:
Code: [Select]
sf::Font _fnt;
_fnt.LoadFromFile("arial.ttf");
CText Foobar(_fnt);

which I wanted to avoid.
2. Create a pointer to the sf::String and create object of it in a constructor:
Code: [Select]
CText()
{
sf::Font _font;
_font.LoadFromFile("arial.ttf");

this->m_string = new sf::String("Text", _font, 40.f);
}

this one would be cool, but when I try to draw the object:
Code: [Select]
void Draw(sf::RenderTarget &target)
{
target.Draw(*m_string);
}

I get a crash. I assume that I am making something stupid but my lack of knowledge disallows me to see what am I doing wrong.

Pages: [1]