当我运行程序时,我在第5行得到一个分段错误,一个SDL_Surface指针正在获取窗口的表面。这是我的代码:
i
这是错误:
#include <stdio.h>
#include <stdlib.h>
#include "SDL2/SDL.h"
SDL_Window* window=NULL;
SDL_Surface* MainSurface=NULL;
SDL_Surface* ImageSurface=NULL;
void ifdebug(int pmbool,const char* str){
if(pmbool==1){
printf(str);
}
}
void NewWindow(int x,int y,int pmbool){
ifdebug(pmbool,"DEBUG^");
SDL_Init(SDL_INIT_VIDEO);
SDL_Event MainEvent;
int IsRunning=1;
window=SDL_CreateWindow("SDL2: Window",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,x,y,SDL_WINDOW_SHOWN);
if(window==NULL){
ifdebug(pmbool,"WINDOW:ERROR<<");
ifdebug(pmbool,SDL_GetError());
ifdebug(pmbool,">>#\n");
SDL_FreeSurface(ImageSurface);
ImageSurface=NULL;
SDL_DestroyWindow(window);
window=NULL;
SDL_Quit();
}
else{
ifdebug(pmbool,"WINDOW:SUCCESS^");
}
MainSurface=SDL_GetWindowSurface(window);
while(IsRunning){
if(SDL_PollEvent(&MainEvent)!=0){
if(MainEvent.type==SDL_QUIT){
ifdebug(pmbool,"QUIT#\n");
IsRunning=0;
SDL_FreeSurface(ImageSurface);
ImageSurface=NULL;
SDL_DestroyWindow(window);
window=NULL;
SDL_Quit();
}
}
}
}
void LoadImage(int pmbool,char* filename){
ImageSurface=SDL_LoadBMP(filename);
if(ImageSurface==NULL||filename==NULL){
ifdebug(pmbool,"DEBUG^");
ifdebug(pmbool,"LOADBMP:ERROR<<");
ifdebug(pmbool,SDL_GetError());
ifdebug(pmbool,">>#\n");
SDL_FreeSurface(ImageSurface);
ImageSurface=NULL;
SDL_DestroyWindow(window);
window=NULL;
SDL_Quit();
}
}
int main(int argc,char* args[]){
NewWindow(600,400,1);
LoadImage(1,"/home/vlad/Desktop/C-lang/BLU.bmp");
SDL_BlitSurface(ImageSurface,NULL,MainSurface,NULL);
SDL_UpdateWindowSurface(window);
return 0;
}
是否与窗口有关?
答案 0 :(得分:0)
> echo "$?"
0
> echo "$result"
./.psp.conf.20150701