0

これは、SDL を使って作業するための単なるトレーニング演習であり、機能の欠如や警告を無視し、すべてがメインにあることを確認します。セグメンテーション違反が発生し続けます。これは、セクションの下の//Initialise TTF, create font pointer, set font and colour then render.セクションで行ったことです。それがないコードは正常に機能します。

#include <SDL2/SDL.h>
#include <SDL/SDL_ttf.h>
#include <stdio.h>

const int SCREEN_WIDTH = 1000;
const int SCREEN_HEIGHT = 1000;

int main(int argc, char* args[])
{
// Set up window, surface, image and font pointers
SDL_Window* gWindow = NULL;
SDL_Surface* gScreenSurface = NULL;
SDL_Surface* gImage1 = NULL;
SDL_Surface* gImage2 = NULL;
SDL_Surface* text = NULL;

// Get a window surface, load images
gWindow = SDL_CreateWindow( "Image in a window, and some text", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
gScreenSurface = SDL_GetWindowSurface(gWindow);
gImage1 = SDL_GetWindowSurface(gWindow);
gImage2 = SDL_GetWindowSurface(gWindow);
gImage1 = SDL_LoadBMP("./Image1.bmp");
gImage2 = SDL_LoadBMP("./Image2.bmp");
------------------------------------------------------
//Initialise TTF, create font pointer, set font and colour then render. 
TTF_Init();
TTF_Font* font;
font = TTF_OpenFont("./LucidaBrightDemiBold.ttf", 24);
SDL_Color text_color = {255, 255, 255, 255};
text = TTF_RenderText_Solid(font, "Using TTF to write stuff", text_color);
-------------------------------------------------------
// Apply the image, update the surface with the image
SDL_BlitSurface(gImage1, NULL, gScreenSurface, NULL); 
SDL_BlitSurface(gImage2, NULL, gScreenSurface, NULL);
SDL_BlitSurface(text, NULL, gScreenSurface, NULL); 
SDL_UpdateWindowSurface( gWindow );                           
SDL_Delay(5000);

// Free surfaces
SDL_FreeSurface(gImage1); 
SDL_FreeSurface(gImage2);
SDL_FreeSurface(text);
//  Nullify surfaces
gImage1 = NULL;
gImage2 = NULL;
text = NULL;      
//Close and nullify window          
SDL_DestroyWindow(gWindow);     
gWindow = NULL;
//Quit images
TTF_Quit();                     
SDL_Quit(); 

return 0;

}

問題は の間にあると思います-------

4

0 に答える 0