我有要使用main.c
进行编译的文件gcc main.c -lSDL2 -lSDL2_image -lSDL2_ttf
,但是运行可执行文件时,出现错误Speicherzugriffsfehler (Speicherabzug geschrieben)
。当我尝试使用gdb进行调试时,我得到
Starting program: /home/qubyte/test
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7ffff708c700 (LWP 13549)]
[New Thread 0x7ffff460e700 (LWP 13550)]
[New Thread 0x7ffff2f3a700 (LWP 13553)]
Thread 1 "u" received signal SIGSEGV, Segmentation fault.
0x00007ffff7e0fef9 in ?? () from /usr/lib/libSDL2_ttf-2.0.so.0
在文件中搜索错误后,我发现此段错误始终出现在此方法中:
TTF_Font* font[1000];
SDL_Surface* surface[1000];
SDL_Texture* text[1000];
void SDL_DrawText(int number, char *ttfPath, char *Text,int TextSize ,SDL_Color color, int X, int Y)
{
int w,h;
font[number] = TTF_OpenFont(ttfPath, TextSize);
surface[number] = TTF_RenderText_Solid(font[number],Text,color);
text[number] = SDL_CreateTextureFromSurface(renderer,surface[number]);
SDL_QueryTexture(text[number],NULL,NULL,&w,&h);
TextRect[number].x = X;
TextRect[number].y = Y;
TextRect[number].w = w;
TextRect[number].h = h;
SDL_RenderCopy(renderer,text[number],NULL,&TextRect[number]);
SDL_FreeSurface(surface[number]);
SDL_DestroyTexture(text[number]);
TTF_CloseFont(font[number]);
}
我弄乱了指针吗?