Ich kriege mal wieder den SDL Fallschirm wenn ich die Bibliothek SDL_ttf benutze:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#include "Text.hpp"
int CText::Init()
{
font=NULL;
m_pScreen=g_pFramework->GetScreen();
if(m_pScreen ==NULL)
cout<<"couldn't get Screen\n";
cout<<m_pScreen<<endl;
if(TTF_Init()==-1)//Initialisiere Fonts
{
printf("TTF_Init: %s\n", TTF_GetError());
return(2);
}
font=TTF_OpenFont("font.ttf", 16);//Lade font.ttf font size=15
cout<<font<<endl;
if(!font)
{
printf("TTF_OpenFont: %s\n", TTF_GetError());
}// handle error
else
cout<<"yeah\n";
TTF_ByteSwappedUNICODE(1);
return(0);
}
void CText::Quit ()
{
TTF_CloseFont(font);
font=NULL; // to be safe...
TTF_Quit();
} // Quit
void CText::Output(int X,int Y,char output[],unsigned short R,unsigned short G,unsigned short B)
{
Text.x=X;
Text.y=Y;
SDL_Color color={R,G,B};
if(!(text_surface=TTF_RenderText_Solid(font,output,color)))
{
//handle error here, perhaps print TTF_GetError at least
}
else
{
SDL_BlitSurface(text_surface,&Text,m_pScreen,NULL);
//perhaps we can reuse it, but I assume not for simplicity.
SDL_FreeSurface(text_surface);
}
}
|
hpp datei
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#ifndef TEXT_HPP
#define TEXT_HPP
#include <SDL_ttf.h>
#include <stdlib.h>
#include <string.h>
#include "Framework.hpp"
class CText
{
public:
int Init ();
void Quit ();
void Output(int X,int Y,char output[],unsigned short R,unsigned short G,unsigned short B);
private:
SDL_Rect Text;
SDL_Surface *text_surface;
TTF_Font *font;
SDL_Surface *m_pScreen;
};
#endif
|
Der Fehler müsste irgendwo nahe der zeile liegen:
font=TTF_OpenFont("font.ttf", 16);//Lade font.ttf font size=15
da die addresse nicht mehr ausgegeben wird.
Der Debugger liefiert nen Code -11
Und das liefert die Console
003A4AC8
Fatal signal: Segmentation Fault (SDL Parachute Deployed)
Press any key to continue
Ich wäre euch sehr verbunden wenn ihr mir Helfen könntet ein großes Loch in den Fallschirm zu machen.