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

Author Topic: Issue instantiating/using Text  (Read 1068 times)

0 Members and 2 Guests are viewing this topic.

Dinipants

  • Newbie
  • *
  • Posts: 16
    • View Profile
Issue instantiating/using Text
« on: April 28, 2017, 07:04:35 pm »
Hey guys,

I'm having a mega headache using the Text class. Whenever I give this class a private Text member, it crashes when I try to run it:

Quote
class Score {
private:
    int score;
    Font* font;
    Text text;      <-------------- giving it a Text member
public:
    Score() {
        this->score = 0;
        this->font = new Font;
        this->font->loadFromFile("./sixty.tff");
    }
    string getScore() {
        return to_string(this->score);
    }
    void increaseScore() {
        this->score += 1;
    }
    void increaseScore(int n) {
        this->score += n;
    }
    Font getFont() {
        return *(this->font);
    }
};

It gives this error message:

Quote
*** Error in `./sfml-app': malloc(): memory corruption: 0x000000000108ac50 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7f4c0516a7e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x8181e)[0x7f4c0517481e]
/lib/x86_64-linux-gnu/libc.so.6(__libc_malloc+0x54)[0x7f4c051765d4]
/usr/lib/x86_64-linux-gnu/libfreetype.so.6(ft_mem_qalloc+0xd)[0x7f4c0427cd7d]
/usr/lib/x86_64-linux-gnu/libfreetype.so.6(ft_mem_alloc+0x28)[0x7f4c0427cdd8]
/usr/lib/x86_64-linux-gnu/libfreetype.so.6(FT_New_Library+0x52)[0x7f4c0427d1d2]
/usr/lib/x86_64-linux-gnu/libfreetype.so.6(FT_Init_FreeType+0x24)[0x7f4c042783e4]
/home/ansah/Downloads/SFML-2.4.2/lib/libsfml-graphics.so.2.4(_ZN2sf4Font12loadFromFileERKSs+0x33)[0x7f4c05e96fe3]
./sfml-app[0x40357f]
./sfml-app[0x4036f8]
./sfml-app[0x402966]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f4c05113830]
./sfml-app[0x402619]
...
Aborted (core dumped)

But if I give other classes a Text member the program runs ok. Everything else in the program works, I;m compiling with these commands:

Quote
g++ -g -c -std=c++11 main.cpp
g++ main.o -o sfml-app -L/home/ansah/Downloads/SFML-2.4.2/lib -lsfml-graphics -lsfml-window -lsfml-system

I'm using Linux and I installed it via sudo apt-get command on the tutorial page. To run it I'm just using ./sudo-app and I;ve tried export LD_LIBRARY_PATH=/home/ansah/Downloads/SFML-2.4.2/lib && ./sfml-app with same results.

For context, I have a class called Game, and I can give that a Text member with no problems. That is also the class which contains a pointer member to a instance of the Score class above, i.e.

Quote
class Game {
private:
    ...
    Score* score;
    Text text;

public:
    Game(CircleShape* shapeInput) {
        ...
        this->score = new Score();
    }
...
}

That doesn't crash on running when I give it a Text member  :-\

I've followed the tutorial and tried the examples in that and looked at multiple forum posts, tried text pointers instead of members, but I can't figure out what's going wrong. Any suggestions welcome.

 

anything