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

Author Topic: Custom Fonts leads to a Segmentation Fault  (Read 5440 times)

0 Members and 2 Guests are viewing this topic.

MakotoYukimura

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Custom Fonts leads to a Segmentation Fault
« on: August 11, 2013, 05:35:36 pm »
Recently I was working on one of my Projects, and I got into writing the UI. Finally got around to adding more Fonts, however when ever I attempt to "Use" a font the program crashes with a Segmentation Fault. I have verified the font data did load, and it's there. However, when I assign an sf::String(SFML 1.6) OR sf::Text(SFML 2.1) the same issue occurs but with a slightly different outcome.

Code: [Select]
No source available for "sf::Font::GetCharacterSize() at 0xb7f4ccd4"

Even using just basic code it still occurs with the same result.
Code: [Select]
sf::Font font;
if(font.LoadFromFile("/home/mike/Bitwise BACKUP/Bitwise/Linux/Game/Graphic/Materials/WLM Grid Font Bold.ttf"))
this->m_text.SetFont(font);

The original font data is stored in a list which is assigned an ID. I changed it to this basic code to see if it was
a problem within the list. Which it wasn't.

Font Path:

Code: [Select]
/home/mike/Bitwise BACKUP/Bitwise/Linux/Game/Graphic/Materials/WLM Grid Font Bold.ttf

Here's the actual class code if it's needed.

.CPP
Code: [Select]
//============================================================================
// Name        : BBasicString.cpp
// Author      : M.Y(Mike)
// Version     : 1.0.0
// Description : A basic "Printable string" for a Graphics Panel.
//============================================================================

#include "BUI_System/BUIObjects.h"
#include "BUI_Text/BBasicString.h"
#include "BUI_System/Properties.hpp"
#include "BUI_System/BUIFontCollection.h"
#include <ec_dbg.h>
/**
 * Default Constructor
 * @param text
 * @param name
 * @param position
 * @param textscale
 * @param R
 * @param G
 * @param B
 * @param A
 * @param CentredText
 */
B_BasicString::B_BasicString ( const std::string& text ,
                               const std::string& name ,
                               EC_V2Point < float > position ,
                               float textscale ,
                               double R ,
                               double G ,
                               double B ,
                               double A ,
                               bool CentredText )
: BUIControl ( name , position )
{
m_centreText = CentredText;

this->SetComponentType ( BUI_TEXT );
this->SetRGAB ( R , G , B , A );
this->SetFontScale ( textscale );
this->SetText ( text );
this->SetPosition ( position );

}
/**
 * Copy Constructor
 * @param source
 */
B_BasicString::B_BasicString ( const B_BasicString& source )
: BUIControl ( source )
{
this->m_R = source.m_R;
this->m_G = source.m_G;
this->m_B = source.m_B;
this->m_A = source.m_A;
this->m_text = sf::String ( source.m_text );
this->m_centreText = source.m_centreText;
}
/**
 * Deconstructor
 */
B_BasicString::~B_BasicString ( )
{
}
/**
 * Gets the runtime type a string
 */
const char* B_BasicString::GetRuntimeType ( ) const{
return BUI_BASICLABEL;
}
/**
 * Callback
 */
void B_BasicString::Callback ( const char* caller )
                               {
}
/**
 * Callback
 */
void B_BasicString::Callback ( BaseCallbackObject* object )
                               {
}
/**
 * Callback
 */
void B_BasicString::Callback ( )
{
}
/**
 * Draws the label
 * @param window
 */
void B_BasicString::Draw ( sf::RenderWindow& window )
                           {
window.Draw ( this->m_text );
}
/**
 * Gets the intensity of ALPHA.
 * @return
 */
double B_BasicString::GetA ( ) const
{
return m_A;
}
/**
 * Sets the intensity of ALPHA.
 * @param A
 */
void B_BasicString::SetA ( double A )
                           {
m_A = A;
}
/**
 * Gets the intensity of BLUE.
 * @return
 */
double B_BasicString::GetB ( ) const
{
return m_B;
}
/**
 * Sets the intensity of BLUE
 * @param B
 */
void B_BasicString::SetB ( double B )
                           {
m_B = B;
}
/**
 * Gets the intensity of GREEN.
 * @return
 */
double B_BasicString::GetG ( ) const
{
return m_G;
}
/**
 * Gets the intensity of RED.
 * @return
 */
double B_BasicString::GetR ( ) const
{
return m_R;
}
/**
 * Sets the text font scale
 * @param fontScale
 */
void B_BasicString::SetFontScale ( float fontScale )
                                   {
m_text.SetSize ( fontScale );
}
/**
 * Gets the text of the label
 * @return
 */
const std::string B_BasicString::GetText ( ) const
{
return std::string ( m_text.GetText ( ) );
}
/**
 * Sets the text of the label
 * @param str
 */
const void B_BasicString::SetText ( const std::string& str )
                                    {
this->m_text.SetText ( str );
}
/**
 * Sets the intensity of RED.
 * @param R
 */
void B_BasicString::SetR ( double R )
                           {
m_R = R;
}
/**
 * Sets the intensity of GREEN.
 * @param G
 */
void B_BasicString::SetG ( double G )
                           {
m_G = G;
}
/**
 * Updates the label
 */
void B_BasicString::Update ( )
{
this->m_text.SetColor ( sf::Color ( m_R , m_G , m_B , m_A ) );
}
/**
 * Sets the RED, GREEN, BLUE and ALPHA color intensities.
 * All default is 255,255,255,255
 * @param R
 * @param G
 * @param B
 * @param A
 */
void B_BasicString::SetRGAB ( double R , double G , double B , double A )
                              {
m_R = R;
m_B = B;
m_G = G;
m_A = A;
}
/**
 * Sets the position of the label on screen.
 * @param Position
 */
void B_BasicString::SetPosition ( const EC_V2Point < float >& Position )
                                  {
BUIControl::SetPosition ( Position );

if ( ! this->m_centreText )
this->m_text.SetPosition ( Position.X , Position.Y );
else {
float positionX = ( this->m_position.X
        - ( this->m_text.GetRect ( ).GetWidth ( ) / 2 ) );
float positionY = ( this->m_position.Y
        - ( this->m_text.GetRect ( ).GetHeight ( ) / 2 ) );
m_text.SetPosition ( positionX , positionY );
}
}
/**
 * Sets the font by ID
 * @param FONT_ID
 */
void B_BasicString::SetActiveFont ( unsigned int FONT_ID ) {

sf::Font font;
if(font.LoadFromFile("/home/mike/Bitwise BACKUP/Bitwise/Linux/Game/Graphic/Materials/WLM.ttf"))
this->m_text.SetFont(font);
}

.H
Code: [Select]
//============================================================================
// Name        : BBasicString.h
// Author      : M.Y(Mike)
// Version     : 1.0.0
// Description : A label
//============================================================================

#ifndef BBASICSTRING_H_
#define BBASICSTRING_H_

#include "BUIControl.h"
#include "BUI_System/BUIObjects.h"

/**
 * A "Label" or a "Drawable Text Control"
 */
class B_BasicString : public BUIControl {
sf::String m_text;
bool m_centreText;
double m_R , m_G , m_B , m_A;
public:
/**
* Default Constructor
* @param text
* @param name
* @param position
* @param textscale
* @param R
* @param G
* @param B
* @param A
*/
B_BasicString ( const std::string& text ,
                const std::string& name ,
                EC_V2Point < float > position ,
                float textscale = BUI_DEFAULT_TEXTSIZE ,
                double R = 255 ,
                double G = 255 ,
                double B = 255 ,
                double A = 255 ,
                bool CentredText = false );

/**
* Copy Constructor
*/
B_BasicString ( const B_BasicString& source );

/**
* Deconstructor
*/
virtual ~B_BasicString ( );
/**
* Gets the type of this class as a string.
* @return
*/
virtual const char* GetRuntimeType ( ) const;
/**
* Callback with a string argument virtual
* @param caller
*/
virtual void Callback ( const char* caller );
/**
* Callback argument
*/
virtual void Callback ( BaseCallbackObject* object );
/**
* Callback with no name
*/
virtual void Callback ( );
/**
* Draws the panel on the screen
* @param window
*/
virtual void Draw ( sf::RenderWindow& window );
/**
* Updates the control
*/
virtual void Update ( );
/**
* Sets the scale of the font
* @param fontScale
*/
virtual void SetFontScale ( float fontScale = BUI_DEFAULT_TEXTSIZE );
/**
* Gets the text of the label
* @return
*/
virtual const std::string GetText ( ) const;
/**
* Sets the text of the label.
* @param str
*/
virtual const void SetText ( const std::string& str );
/**
* Gets the intensity of ALPHA.
* @return
*/
virtual double GetA ( ) const;
/**
* Sets the intensity of ALPHA.
* @param G
*/
virtual void SetA ( double A );
/**
* Gets the intensity of BLUE.
* @return
*/
virtual double GetB ( ) const;
/**
* Sets the intensity of BLUE.
* @param G
*/
virtual void SetB ( double B );
/**
* Gets the intensity of GREEN.
* @return
*/
virtual double GetG ( ) const;
/**
* Sets the intensity of GREEN.
* @param G
*/
virtual void SetG ( double G );
/**
* Gets the intensity of RED.
* @return
*/
virtual double GetR ( ) const;
/**
* Sets the intensity of RED.
* @param R
*/
virtual void SetR ( double R );
/**
* Sets the RED, GREEN, BLUE and ALPHA color intensities.
* All default is 255,255,255,255
* @param R
* @param G
* @param B
* @param A
*/
virtual void SetRGAB ( double R = 255 ,
                       double G = 255 ,
                       double B = 255 ,
                       double A = 255 );

/**
* Sets the position of label on screen
* @param Position
*/
virtual void SetPosition ( const EC_V2Point < float >& Position );
/** Sets the font by ID.
* @param FONT_ID
*/
virtual void SetActiveFont(unsigned int FONT_ID);
};

#endif /* BBASICSTRING_H_ */

Engine's Log Output(Probably not much help but I'll post it anyway).
Code: [Select]
[MSG]::[BUI_SetScreenRes]: ScreenFix: Set Frame Size to [360,230]
[MSG]::[BUI_SetScreenRes]: ScreenFix: Set Window Stat Size to [360,230]
[MSG]::[BUI_SetScreenRes]: BUI_SetScreenRes: Screen Fix is enabled
[MSG]::[BPixelProcessor::FromPixels]: Reading from [0,0] to [16,16]
[MSG]::[Textures::AddCategory]: Created Texture Category Game
[MSG]::[Textures::AddTextureKey]: 0 is now a child of category Game
[MSG]::[]: Tile ID 0 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [16,0] to [32,16]
[MSG]::[Textures::AddTextureKey]: 1 is now a child of category Game
[MSG]::[]: Tile ID 1 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [32,0] to [48,16]
[MSG]::[Textures::AddTextureKey]: 2 is now a child of category Game
[MSG]::[]: Tile ID 2 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [48,0] to [64,16]
[MSG]::[Textures::AddTextureKey]: 3 is now a child of category Game
[MSG]::[]: Tile ID 3 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [64,0] to [80,16]
[MSG]::[Textures::AddTextureKey]: 4 is now a child of category Game
[MSG]::[]: Tile ID 4 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [80,0] to [96,16]
[MSG]::[Textures::AddTextureKey]: 5 is now a child of category Game
[MSG]::[]: Tile ID 5 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [0,16] to [16,32]
[MSG]::[Textures::AddTextureKey]: 10 is now a child of category Game
[MSG]::[]: Tile ID 10 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [16,16] to [32,32]
[MSG]::[Textures::AddTextureKey]: 11 is now a child of category Game
[MSG]::[]: Tile ID 11 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [32,16] to [48,32]
[MSG]::[Textures::AddTextureKey]: 12 is now a child of category Game
[MSG]::[]: Tile ID 12 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [48,16] to [64,32]
[MSG]::[Textures::AddTextureKey]: 13 is now a child of category Game
[MSG]::[]: Tile ID 13 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [64,16] to [80,32]
[MSG]::[Textures::AddTextureKey]: 14 is now a child of category Game
[MSG]::[]: Tile ID 14 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [64,16] to [80,32]
[MSG]::[Textures::AddTextureKey]: 15 is now a child of category Game
[MSG]::[]: Tile ID 15 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [80,16] to [96,32]
[MSG]::[Textures::AddTextureKey]: 16 is now a child of category Game
[MSG]::[]: Tile ID 16 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [96,16] to [112,32]
[MSG]::[Textures::AddTextureKey]: 17 is now a child of category Game
[MSG]::[]: Tile ID 17 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [0,32] to [16,48]
[MSG]::[Textures::AddTextureKey]: 20 is now a child of category Game
[MSG]::[]: Tile ID 20 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [16,32] to [32,48]
[MSG]::[Textures::AddTextureKey]: 21 is now a child of category Game
[MSG]::[]: Tile ID 21 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [32,32] to [48,48]
[MSG]::[Textures::AddTextureKey]: 22 is now a child of category Game
[MSG]::[]: Tile ID 22 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [48,32] to [64,48]
[MSG]::[Textures::AddTextureKey]: 23 is now a child of category Game
[MSG]::[]: Tile ID 23 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [64,32] to [80,48]
[MSG]::[Textures::AddTextureKey]: 24 is now a child of category Game
[MSG]::[]: Tile ID 24 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [0,48] to [16,64]
[MSG]::[Textures::AddTextureKey]: 30 is now a child of category Game
[MSG]::[]: Tile ID 30 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [16,48] to [32,64]
[MSG]::[Textures::AddTextureKey]: 31 is now a child of category Game
[MSG]::[]: Tile ID 31 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [32,48] to [48,64]
[MSG]::[Textures::AddTextureKey]: 32 is now a child of category Game
[MSG]::[]: Tile ID 32 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [48,48] to [64,64]
[MSG]::[Textures::AddTextureKey]: 33 is now a child of category Game
[MSG]::[]: Tile ID 33 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [64,48] to [80,64]
[MSG]::[Textures::AddTextureKey]: 34 is now a child of category Game
[MSG]::[]: Tile ID 34 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [0,64] to [16,80]
[MSG]::[Textures::AddTextureKey]: 40 is now a child of category Game
[MSG]::[]: Tile ID 40 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [16,64] to [32,80]
[MSG]::[Textures::AddTextureKey]: 41 is now a child of category Game
[MSG]::[]: Tile ID 41 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [32,64] to [48,80]
[MSG]::[Textures::AddTextureKey]: 42 is now a child of category Game
[MSG]::[]: Tile ID 42 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [48,64] to [64,80]
[MSG]::[Textures::AddTextureKey]: 43 is now a child of category Game
[MSG]::[]: Tile ID 43 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [0,80] to [16,96]
[MSG]::[Textures::AddTextureKey]: 50 is now a child of category Game
[MSG]::[]: Tile ID 50 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [16,80] to [32,96]
[MSG]::[Textures::AddTextureKey]: 51 is now a child of category Game
[MSG]::[]: Tile ID 51 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [32,80] to [48,96]
[MSG]::[Textures::AddTextureKey]: 52 is now a child of category Game
[MSG]::[]: Tile ID 52 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [48,80] to [64,96]
[MSG]::[Textures::AddTextureKey]: 53 is now a child of category Game
[MSG]::[]: Tile ID 53 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [0,80] to [16,96]
[MSG]::[Textures::AddTextureKey]: 60 is now a child of category Game
[MSG]::[]: Tile ID 60 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [16,80] to [32,96]
[MSG]::[Textures::AddTextureKey]: 61 is now a child of category Game
[MSG]::[]: Tile ID 61 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [32,80] to [48,96]
[MSG]::[Textures::AddTextureKey]: 62 is now a child of category Game
[MSG]::[]: Tile ID 62 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [48,80] to [64,96]
[MSG]::[Textures::AddTextureKey]: 63 is now a child of category Game
[MSG]::[]: Tile ID 63 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [0,96] to [16,112]
[MSG]::[Textures::AddTextureKey]: 70 is now a child of category Game
[MSG]::[]: Tile ID 70 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [16,96] to [32,112]
[MSG]::[Textures::AddTextureKey]: 71 is now a child of category Game
[MSG]::[]: Tile ID 71 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [32,96] to [48,112]
[MSG]::[Textures::AddTextureKey]: 72 is now a child of category Game
[MSG]::[]: Tile ID 72 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [48,96] to [64,112]
[MSG]::[Textures::AddTextureKey]: 73 is now a child of category Game
[MSG]::[]: Tile ID 73 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [0,112] to [16,128]
[MSG]::[Textures::AddTextureKey]: 80 is now a child of category Game
[MSG]::[]: Tile ID 80 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [16,112] to [32,128]
[MSG]::[Textures::AddTextureKey]: 81 is now a child of category Game
[MSG]::[]: Tile ID 81 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [64,112] to [80,128]
[MSG]::[Textures::AddTextureKey]: 82 is now a child of category Game
[MSG]::[]: Tile ID 82 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [80,112] to [96,128]
[MSG]::[Textures::AddTextureKey]: 83 is now a child of category Game
[MSG]::[]: Tile ID 83 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [96,112] to [112,128]
[MSG]::[Textures::AddTextureKey]: 84 is now a child of category Game
[MSG]::[]: Tile ID 84 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [0,128] to [16,144]
[MSG]::[Textures::AddTextureKey]: 90 is now a child of category Game
[MSG]::[]: Tile ID 90 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [16,128] to [32,144]
[MSG]::[Textures::AddTextureKey]: 91 is now a child of category Game
[MSG]::[]: Tile ID 91 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [32,144] to [48,160]
[MSG]::[Textures::AddTextureKey]: 100 is now a child of category Game
[MSG]::[]: Tile ID 100 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [48,144] to [64,160]
[MSG]::[Textures::AddTextureKey]: 101 is now a child of category Game
[MSG]::[]: Tile ID 101 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [0,160] to [16,176]
[MSG]::[Textures::AddTextureKey]: 110 is now a child of category Game
[MSG]::[]: Tile ID 110 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [16,160] to [32,176]
[MSG]::[Textures::AddTextureKey]: 111 is now a child of category Game
[MSG]::[]: Tile ID 111 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [32,160] to [48,176]
[MSG]::[Textures::AddTextureKey]: 112 is now a child of category Game
[MSG]::[]: Tile ID 112 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [48,160] to [64,176]
[MSG]::[Textures::AddTextureKey]: 113 is now a child of category Game
[MSG]::[]: Tile ID 113 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [64,160] to [80,176]
[MSG]::[Textures::AddTextureKey]: 114 is now a child of category Game
[MSG]::[]: Tile ID 114 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [80,160] to [96,176]
[MSG]::[Textures::AddTextureKey]: 115 is now a child of category Game
[MSG]::[]: Tile ID 115 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [96,160] to [112,176]
[MSG]::[Textures::AddTextureKey]: 116 is now a child of category Game
[MSG]::[]: Tile ID 116 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [112,160] to [128,176]
[MSG]::[Textures::AddTextureKey]: 117 is now a child of category Game
[MSG]::[]: Tile ID 117 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [128,160] to [144,176]
[MSG]::[Textures::AddTextureKey]: 118 is now a child of category Game
[MSG]::[]: Tile ID 118 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [144,160] to [160,176]
[MSG]::[Textures::AddTextureKey]: 119 is now a child of category Game
[MSG]::[]: Tile ID 119 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [160,160] to [176,176]
[MSG]::[Textures::AddTextureKey]: 120 is now a child of category Game
[MSG]::[]: Tile ID 120 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [176,160] to [192,176]
[MSG]::[Textures::AddTextureKey]: 121 is now a child of category Game
[MSG]::[]: Tile ID 121 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [192,160] to [208,176]
[MSG]::[Textures::AddTextureKey]: 122 is now a child of category Game
[MSG]::[]: Tile ID 122 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [208,160] to [224,176]
[MSG]::[Textures::AddTextureKey]: 123 is now a child of category Game
[MSG]::[]: Tile ID 123 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [64,144] to [80,160]
[MSG]::[Textures::AddTextureKey]: 124 is now a child of category Game
[MSG]::[]: Tile ID 124 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [80,144] to [96,160]
[MSG]::[Textures::AddTextureKey]: 125 is now a child of category Game
[MSG]::[]: Tile ID 125 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [0,176] to [16,192]
[MSG]::[BPixelProcessor::FromPixels]: Reading from [0,192] to [16,208]
[MSG]::[BPixelProcessor::FromPixels]: Reading from [16,176] to [32,192]
[MSG]::[BPixelProcessor::FromPixels]: Reading from [16,192] to [32,208]
[MSG]::[Textures::AddTextureKey]: 131 is now a child of category Game
[MSG]::[]: Tile ID 131 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [48,176] to [64,192]
[MSG]::[BPixelProcessor::FromPixels]: Reading from [48,192] to [64,208]
[MSG]::[BPixelProcessor::FromPixels]: Reading from [64,176] to [80,192]
[MSG]::[BPixelProcessor::FromPixels]: Reading from [64,192] to [80,208]
[MSG]::[Textures::AddTextureKey]: 132 is now a child of category Game
[MSG]::[]: Tile ID 132 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [96,176] to [112,192]
[MSG]::[BPixelProcessor::FromPixels]: Reading from [96,192] to [112,208]
[MSG]::[BPixelProcessor::FromPixels]: Reading from [96,208] to [112,224]
[MSG]::[BPixelProcessor::FromPixels]: Reading from [112,176] to [128,192]
[MSG]::[BPixelProcessor::FromPixels]: Reading from [112,192] to [128,208]
[MSG]::[BPixelProcessor::FromPixels]: Reading from [112,208] to [128,224]
[MSG]::[Textures::AddTextureKey]: 133 is now a child of category Game
[MSG]::[]: Tile ID 133 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [96,0] to [112,16]
[MSG]::[Textures::AddTextureKey]: 1000 is now a child of category Game
[MSG]::[]: Tile ID 1000 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [112,0] to [128,16]
[MSG]::[Textures::AddTextureKey]: 1001 is now a child of category Game
[MSG]::[]: Tile ID 1001 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [128,0] to [144,16]
[MSG]::[Textures::AddTextureKey]: 1002 is now a child of category Game
[MSG]::[]: Tile ID 1002 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [0,0] to [16,16]
[MSG]::[Textures::AddTextureKey]: 2000 is now a child of category Game
[MSG]::[]: Tile ID 2000 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [16,0] to [32,16]
[MSG]::[Textures::AddTextureKey]: 2001 is now a child of category Game
[MSG]::[]: Tile ID 2001 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [32,0] to [48,16]
[MSG]::[Textures::AddTextureKey]: 2002 is now a child of category Game
[MSG]::[]: Tile ID 2002 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [48,0] to [64,16]
[MSG]::[Textures::AddTextureKey]: 2003 is now a child of category Game
[MSG]::[]: Tile ID 2003 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [0,16] to [16,32]
[MSG]::[Textures::AddTextureKey]: 2004 is now a child of category Game
[MSG]::[]: Tile ID 2004 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [16,16] to [32,32]
[MSG]::[Textures::AddTextureKey]: 2005 is now a child of category Game
[MSG]::[]: Tile ID 2005 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [32,16] to [48,32]
[MSG]::[Textures::AddTextureKey]: 2006 is now a child of category Game
[MSG]::[]: Tile ID 2006 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [48,16] to [64,32]
[MSG]::[Textures::AddTextureKey]: 2007 is now a child of category Game
[MSG]::[]: Tile ID 2007 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [0,32] to [16,48]
[MSG]::[Textures::AddTextureKey]: 2008 is now a child of category Game
[MSG]::[]: Tile ID 2008 added successfully
[MSG]::[BPixelProcessor::FromPixels]: Reading from [16,32] to [32,48]
[MSG]::[Textures::AddTextureKey]: 2009 is now a child of category Game
[MSG]::[]: Tile ID 2009 added successfully
[MSG]::[Folders::GetFiles]: Found Directory Level1
[MSG]::[Folders::GetFiles]: Found 1 directories matching in path /home/mike/Bitwise BACKUP (copy)/Bitwise/Linux/Game/Script/Level
[MSG]::[Folders::GetFiles]: Found 8 objects ( With Ext 'Directory) in path /home/mike/Bitwise BACKUP (copy)/Bitwise/Linux/Game/Script/Level/Level1
[MSG]::[BLevelProcessor::Commit]: Load Level Content:  by Makoto(Mike)
[MSG]::[B_LevelDataProcessor::ProcessLevelFile]: Processing Job A.ldf
[MSG]::[B_LevelDataProcessor::ProcessLevelFile]: Starting construction for level Plains
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]0:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]1:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]2:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]3:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]4:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]5:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]6:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]7:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]8:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]9:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]10:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]11:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]12:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessLevelFile]: Finished Job /home/mike/Bitwise BACKUP (copy)/Bitwise/Linux/Game/Script/Level/Level1/A.ldf
[MSG]::[B_LevelDataProcessor::ProcessLevelFile]: Processing Job B.ldf
[MSG]::[B_LevelDataProcessor::ProcessLevelFile]: Starting construction for level Plains2
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]0:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]1:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]2:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]3:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]4:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]5:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]6:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]7:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]8:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]9:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]10:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]11:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessGenericMapTile]: Swapped Tile [L]2:[X]12:[Y]0
[MSG]::[B_LevelDataProcessor::ProcessLevelFile]: Finished Job /home/mike/Bitwise BACKUP (copy)/Bitwise/Linux/Game/Script/Level/Level1/B.ldf
[MSG]::[BLevels::AddLevel]: Level collection "Level1" has been added.
[MSG]::[EventQue]: Resizing Window..
[MSG]::[BUI_SetScreenRes]: ScreenFix: Set Frame Size to [360,230]
[MSG]::[BUI_SetScreenRes]: ScreenFix: Set Window Stat Size to [1678,1020]
[MSG]::[BUI_SetScreenRes]: BUI_SetScreenRes: Screen Fix is enabled

The IDE outputed no errors on build for my project. SFML 2.1 and 1.6 seem to have the problem in the same area. After assigning the fonts it crashes.

OS Is Ubuntu 12.04 LTS running Gnome 3. Graphics Card is a 9800GT 1024mb.


Any solutions?
« Last Edit: August 11, 2013, 06:03:49 pm by MakotoYukimura »

Barlog

  • Guest
Re: Custom Fonts leads to a Segmentation Fault
« Reply #1 on: August 11, 2013, 06:37:13 pm »
Greetings.
Have you tried font loading with minimal basic code?
Please check if you have libfreetype installed. Just for sure.

Please try this code and let us know about outcome.

#include <SFML/Graphics.hpp>
#include <iostream>
#include <sstream>

int main()
{
    sf::RenderWindow window;
    window.create(sf::VideoMode(640, 480, 32), "font test");

    sf::Clock clock;

    std::string fontPath("/home/mike/Bitwise BACKUP/Bitwise/Linux/Game/Graphic/Materials/WLM Grid Font Bold.ttf");
    sf::Font font;
    sf::Text text;
    if (!font.loadFromFile(fontPath))
    {
        std::cout << "path is not found";
        return 0;
    }

    text.setFont(font);
    text.setCharacterSize(24);

    while(window.isOpen())
    {
        sf::Event event;

        while(window.pollEvent(event))
        {
            switch(event.type)
            {
                case sf::Event::Closed:
                    {
                        window.close();
                        break;
                    }
                case sf::Event::KeyPressed:
                    {
                        if(event.key.code == sf::Keyboard::Escape)
                        {
                            window.close();
                            break;
                        }
                    }
                    default: break;
            }
        }

        std::stringstream ss;
        std::string t;
        ss << clock.getElapsedTime().asSeconds();
        ss >> t;

        text.setString(t);

        window.draw(text);
        window.display();
        window.clear();
    }
}
 

MakotoYukimura

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: Custom Fonts leads to a Segmentation Fault
« Reply #2 on: August 11, 2013, 06:51:56 pm »
That works with 1.6(after converted) and 2.1. So it seems to be project related, but I can't point to where the issue is. Since my debugger's breakpoints stopped working sometime ago(Just show up as white dots, and are disabled due to something in GDB).



« Last Edit: August 11, 2013, 06:59:42 pm by MakotoYukimura »

The Hatchet

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Email
Re: Custom Fonts leads to a Segmentation Fault
« Reply #3 on: August 11, 2013, 07:54:18 pm »
void B_BasicString::SetActiveFont ( unsigned int FONT_ID ) {

         sf::Font font;
         if(font.LoadFromFile("/home/mike/Bitwise BACKUP/Bitwise/Linux/Game/Graphic/Materials/WLM.ttf"))
                 this->m_text.SetFont(font);
}
 

After you set the active font it loses scope and is destroyed when the thread leaves this method.

MakotoYukimura

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: Custom Fonts leads to a Segmentation Fault
« Reply #4 on: August 11, 2013, 08:11:49 pm »
That's true, but even when I had a list of fonts attached that were there and constantly accessible the same thing would occur. Which is why I attempted to simplify it.

Unless I have to pass it in by Reference, then that changes everything. Because the documentation says Fonts use a lot of memory by themselves, so duplicating them may be a bad idea.

Basically, the list imports them after from the main project I call BUI_RegisterFont(<ID>, <stringpath>) and stores them in a list of registered fonts, which then are pointed towards controls. Then when I want to use a font, I retrieve it from the ID.

The list does not use Pointers, and when it did there was no difference.

However, you're correct about it being out of scope. By setting it to use a local font, the program would run properly. So I should investigate it a little more.

But I would appreciate it if SFML would atleast inform me about there being a problem with an object. I did not see anything about the "scope" being mentioned when I went to look up how to use them a while ago.

Seems to work fine now:





« Last Edit: August 12, 2013, 09:54:47 am by MakotoYukimura »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: Custom Fonts leads to a Segmentation Fault
« Reply #5 on: August 11, 2013, 08:42:26 pm »
It's in the tutorial or documentation or both.
On the other hand you understand enough of C++ to notice the by rederence pass, thus figuering out the dependency on your own. Or realize the a font is a (heavy) resource, thus you'll have to keep it around. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MakotoYukimura

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: Custom Fonts leads to a Segmentation Fault
« Reply #6 on: August 11, 2013, 08:55:32 pm »
When I got into C++ about 3 weeks ago(After coming from C# .NET) everything pretty much just fell from the sky, there was a few things though I still had to learn. Pointers, some Syntax, Etc. But now things seem to be working out quite well.

My game uses memory quite a bit, but that's due to tiles. Levels typically only load when they're about to be played, and then deallocated and deleted after they've been played - recreated again later if they want to play it again. I'm sure not going to load 2000 levels and use 12 gigs of memory, that's just not very bright. Each level contains a file that lists level parts, when the first level loads, all the level parts for that one are allocated and then played within a sequence to each other. I load them dynamically so save memory and time, it just temporarily stores the tile IDs in a 2D string array to be processed when the time comes for them to be created.

The screen res is very very small, it's 360x230(I know it's weird) but the maps are made of 20x14 tiles measured 16x16 and the game is designed to have a "Retro" feel to it.


But anyway, I did a bit of tweaking and the font list is functioning as I was wanting it too. Thanks for the help guys.
« Last Edit: August 11, 2013, 08:57:40 pm by MakotoYukimura »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: Custom Fonts leads to a Segmentation Fault
« Reply #7 on: August 11, 2013, 09:32:34 pm »
Yeah managing the used memory is smart. I hope you're using the RAII paradigm instead of actually using new/delete pairs. If not you might want to read up on it, it's exactly what's going on with all of SFML's resources. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MakotoYukimura

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: Custom Fonts leads to a Segmentation Fault
« Reply #8 on: August 12, 2013, 05:07:41 am »
Unfortunately most of the logic used for memory allocation just uses delete/new to allocate/deallocate it. I did not know about "RAII Paradigms" until you told me about it.  Even though the code itself works fine, I'll be sure to look it up.

Everything when it allocates throws exceptions or warnings if there's a problem. Exceptions will call and the engine itself will exit with a critical error message printed to console/log file to describe the problem. Warnings are usually in places that won't cause crashes and such things. I did it this way so everything will run correctly, but exceptions are only thrown if the the project is compiled with the -DEBUGGER flag. The UI Library uses code to initialize the type of safety it uses. If I tell it not to use exceptions or print messages, it will just bypass the error messages and deleting(if applicable) the bad objects. The only flaw I can really see is the objects(on load failure, or other severe errors) will commit suicide, panels are assigned to a vector which is then updated/drawn from the main loop. Each child of the panel(buttons, etc) are updated/drawn with the panel. If a Panel or a Panel's Child were to just randomly disappear, the code is written to automatically deal with it and delete it from the list of components.

My experience in C++ isn't very long, but I just know the basics of programming from C#. I learned it several years ago, while writing it in XNA. Eventually realized 'Why am I wasting my time with this'? I hated developers for not supporting Linux in the first place, yet there I was using a single platform system.

On the good side of things I corrected the debugger that was throwing a fit. But for some reason my IDE won't recognize project paths, absolute paths are necessary for some files. Which is fine, this code isn't meant to be compiled on machines that don't have same path. But I'm working on resolving it on the Eclipse support Forums under the Category "CDT".

« Last Edit: August 12, 2013, 10:50:12 am by MakotoYukimura »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
AW: Custom Fonts leads to a Segmentation Fault
« Reply #9 on: August 12, 2013, 12:43:37 pm »
It sounds like you're doing things a bit safer than most other people out there, unfortunately there are just too much area to cover when using new/delete, so much that it isn't really possible to guarantee 100% safty. With the use of RAII and possibly some C++11 features you can drastically reduce your code base, while making memory management safe. A nice example of this can be found next to other information, in a thread by Nexus. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MakotoYukimura

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: Custom Fonts leads to a Segmentation Fault
« Reply #10 on: August 12, 2013, 02:08:00 pm »
That's a rather unique way of doing things. I'll be sure to implement it in the new objects(and future projects). The current size of the project would take days to rewrite the data. Seeing how the Level Processor class has over 5,000 lines of code. That's because the Level Builder is powered by my own version of ASM. I wanted to do something that would be fun, and not just a plain old block of chars. It also makes it a lot easier to create tiles, because it offers the ability to use basic loops.

Code: [Select]
start_level Plains
mov minx,0
mov miny,0
mov maxx,1
mov maxy,1
mov layer,2
invoke zeromode
invoke cursor_reset
mov blt,0
mov addry,0
mov addrx,0
apply addrx,13 >paste
add addry,1
apply addrx,13 >paste
res addry
res addrx
end_level

My level editor exports the map file into this code, which is read by the game itself. I guess you can say it "Compiles" data to an editable text file with an extension of .ldf

But, anyway I'll use that new way of resource management and attempt to make something safer. Thanks for the information, it may save me a lot of time and grief in near future. I am finished here, and I honestly hope I don't get more unknown problems like this in the future. I tried for 2 hours before posting here because I didn't want to post for something simple - I guess you can say it was?

Byes
« Last Edit: August 12, 2013, 02:11:26 pm by MakotoYukimura »