我总是得到segmentation fault core dumpet error
。我不知道出了什么问题,我知道我不会在最后释放这些东西,但这不是原因(我猜)。我正在尝试创建一个非常简单的应用程序来呈现您放入其中的任何文本,我无法使其正常工作。
#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
int main(int argc, char *argv[])
{
SDL_Window *window = NULL;
SDL_Renderer* renderTarget = NULL;
SDL_Init(SDL_INIT_VIDEO);
TTF_Init();
window = SDL_CreateWindow("potato", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN);
renderTarget = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
TTF_Font* Sans = TTF_OpenFont("Sans.ttf",30);
SDL_Color White = {255, 255, 255};
SDL_Surface* surfaceMessage = TTF_RenderText_Solid(Sans, "put your text here", White);
SDL_Texture* Message = SDL_CreateTextureFromSurface(renderTarget, surfaceMessage);
SDL_Rect Message_rect = {50,50,300,300};
bool isRunning = true;
SDL_Event ev;
while (isRunning)
{
while (SDL_PollEvent(&ev) != 0)
{
if (ev.type == SDL_QUIT)
isRunning = false;
}
SDL_RenderClear(renderTarget);
SDL_RenderCopy(renderTarget, Message, NULL, &Message_rect); //
SDL_RenderPresent(renderTarget);
}
SDL_Quit();
TTF_Quit();
return 0;
}