Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

1

12.04.2012, 17:31

C++ und SDL_ttf (in Code::Blocks)

Hallo zusammen,



In den letzten Wochen habe ich mit der Programmierung von grafischen Oberflächen mittels SDL beschäftigt. Das ganze hat nun soweit auch ganz gut geklappt nur bräuchte ich nun Text. Daher habe ich die Bibliothek SDL_ttf heruntergeladen und folgendermasen installiert:



Header-File SDL_ttf.h in .../.../CodeBlocks/SDL/include kopiert



SDL_ttf.lib in .../.../CodeBlocks/SDL/lib kopiert



Die DLL's (x86/32Bit) habe ich in C:/Windows/system32 sowie in C/Windows/SysWOW64 kopiert (sicher is sicher ;-) )


Danach habe ich dann in Code::Blocks unter Setting->Compiler and Debugger -> Linker Settings bei Lnkk librarys die SDL_ttf.lib gesucht und angegeben.



Den Sourcecode habe ich aus einem Tutorial übernommen(http://www.aaroncox.net/tutorials/2dtutorials/sdltext.html), habe jedoch auch andere ausprobiert.



Das Problem ist nun, dass jedes mal wenn ich den Compiler starte das Fenster erscheint und dann rechts unten (im Windows da wo die Uhr is) ein kleines gelbes Fenster erchein in welchem steht:

Zitat

"SIGNAL RESIVED:Program resived signal SIGSEGV, Signal fault"





Das Programm läuft daraufhin zwar weiter aber das gesamte Fenster bleibt schwarz.
Ein kleiner gelber Pfeil zeigt auf folgende Zeile:

C-/C++-Quelltext

1
SDL_Surface* textSurface = TTF_RenderText_Shaded(font, "This is my text.",foregroundColor, backgroundColor);




Der Debugger gibt folgendes aus:

Zitat

Building to ensure sources are up-to-date

Build succeeded

Selecting target:

Debug

Adding source dir: D:\Programmieren\projekte\SDL_TTF3\

Adding source dir: D:\Programmieren\projekte\SDL_TTF3\

Adding file: bin\Debug\SDL_TTF3.exe

Starting debugger:

done

Registered new type: wxString

Registered new type: STL String

Registered new type: STL Vector

Setting breakpoints

Debugger name and version: GNU gdb 6.8

Child process PID: 6892

Program received signal SIGSEGV, Segmentation fault.

In TTF_SizeUNICODE () (C:\Windows\SysWOW64\SDL_ttf.dll)

At D:\Programmieren\projekte\SDL_TTF3\main.cpp:22




Der Code:

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include 

#include  





const int WINDOW_WIDTH = 640; 

const int WINDOW_HEIGHT = 480; 

const char* WINDOW_TITLE = "SDL Start"; 





int main(int argc, char **argv) 

 { 

    SDL_Init( SDL_INIT_VIDEO ); 

    TTF_Init(); 

    SDL_Surface* screen = SDL_SetVideoMode( WINDOW_WIDTH, WINDOW_HEIGHT, 0,SDL_HWSURFACE | SDL_DOUBLEBUF ); 

    SDL_WM_SetCaption( WINDOW_TITLE, 0 ); 

    TTF_Font* font = TTF_OpenFont("ARIAL.TTF", 12); 

    SDL_Color foregroundColor = { 255, 255, 255 }; 

    SDL_Color backgroundColor = { 0, 0, 255 }; 

    SDL_Surface* textSurface = TTF_RenderText_Shaded(font, "This is my text.",foregroundColor, backgroundColor); // Pass zero for width and height to draw the whole surface 

    SDL_Rect textLocation = { 100, 100, 0, 0 }; 

    SDL_Event event; 

    bool gameRunning = true; 

    while (gameRunning) 

    { 

          if (SDL_PollEvent(&event)) 

          { 

                if (event.type == SDL_QUIT) 

                { 

                      gameRunning = false; 

                } 

          }    

         SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); 

          SDL_BlitSurface(textSurface, NULL, screen, &textLocation); 

          SDL_Flip(screen);  

    } 

    SDL_FreeSurface(textSurface); 

    TTF_CloseFont(font); 

    TTF_Quit();

    SDL_Quit(); 

    return 0; 

 }












Ich hoffe irgendjemand hat mir eine Idee bin schon am verzweifeln!!



MfG Pat711



Edit: noch einige Ergänzungen:



Code::Blocks 10.05



Windows 7 x64

Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »Pat711« (12.04.2012, 17:49)


2

13.04.2012, 13:28

Also ich habe hier noch den Call Stack, falls der weiter hilft.

Zitat

#0 6F4C2A9D TTF_SizeUNICODE() (D:\Programmieren\projekte\SDL_TTF3\SDL_ttf.dll:??)
#1 6F4C349E TTF_RenderUNICODE_Shaded() (D:\Programmieren\projekte\SDL_TTF3\SDL_ttf.dll:??)
#2 6F4C394A TTF_RenderText_Shaded() (D:\Programmieren\projekte\SDL_TTF3\SDL_ttf.dll:??)
#3 004013C1 SDL_main(argc=1, argv=0x9e1758) (D:\Programmieren\projekte\SDL_TTF3\main.cpp:22)
#4 00402069 console_main(argc=1, argv=0x9e1758) (./src/main/win32/SDL_win32_main.c:210)
#5 00000000 0x00000001 in ??() (??:??)
#6 00000000 0x009e1758 in ??() (??:??)
#7 00000000 0x0000001c in ??() (??:??)
#8 00000000 0x00000000 in ??() (??:??)


Sry wegen Doppelpost aber bei edit verziehts mir irgendwie alles. X(

Der Fehler SIGSEGV scheint ja aufzutreten wenn ein Pointer auf einen ungültigen Speicherbereich zeigt. Kann mir aber nicht erklären wo das so sein soll.
Ist vll doch ein Teil der lib falsch eingebunden?

MfG Pat711

3

15.04.2012, 16:54

Ich habe das Problem nun gelöst. Für alle die auf ähnliche Probelme stoßen:

Bei mir war das Poblem dass die Schriftart nicht im selben Ordner lag, da ich davon augegangen bin dass das Programm auch in dem speziellen Ordner "Schriftarten" von Windows findet. Zudem bin ich nicht ganz sicher ob alle DLL Dateien an der korrekten Stelle waren.

MfG Pat711

Werbeanzeige