간단한 SDL 응용 프로그램을 만들고 있지만, 어떤 이유로 내 창이 멈추지 않고 프로그램이 중단됩니다. 코드는 다음과 같습니다.내 SDL 응용 프로그램 창이 튀어 나와 즉시 사라집니다.
bool CApp::onInit() {
if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
return false;
display = SDL_SetVideoMode(WIDTH, HEIGHT, BPP, SDL_HWSURFACE | SDL_DOUBLEBUF);
// Window pops up and disappears here.
if(display == nullptr) // display is NOT null
return false;
// Load the grid
Grid = CSurface::onLoad("Resources\\Images\\Grid.png");
if(Grid == nullptr)
return false; // Program crashes here due to onLoad returning nullptr.
// Load the X mark
X = CSurface::onLoad("Resources\\Images\\X.png");
if(X == nullptr)
return false;
// Load the O mark
O = CSurface::onLoad("Resources\\Images\\O.png");
if(X == nullptr)
return false;
return true;
}
프로그램 오류가 발생한 위치를 확인하십시오.
여기에 CSurface::onLoad()
기능이 있습니다.
SDL_Surface* CSurface::onLoad(char* File) {
SDL_Surface* surfTemp = nullptr; // Temporary Surface
SDL_Surface* surfReturn = nullptr; // Return Surface
surfTemp = SDL_LoadBMP(File); // This returns a nullptr for some reason
if(surfTemp == nullptr)
return nullptr; // This is the culprit for the program crashing.
// Optimize and free our surface.
surfReturn = SDL_DisplayFormat(surfTemp);
SDL_FreeSurface(surfTemp);
return surfReturn;
}
왜 내가 작동하지 않는지 알 수 없습니다. 전에는 효과가 있었지만 이제는 충돌합니다!
왜 파일 이름에 //가 있습니까? 또한 IMG_Load (File)로 전환하면 여전히 null이 반환됩니까? 올바른 위치에 파일이 있습니까? 액세스 권한을 높여야합니까? – Chemistpp
'\\'는 이스케이프 문자입니다. – Tux