SDL_Surface를로드 한 후 내 자신의 정의 된 클래스 인 Actor 내에서 내 SDL_Surface가 NULL로 돌아갑니다. 많은 콘솔 출력과 GDB를 사용하여 오류의 위치를 찾습니다. Actor 클래스는 SDL_Surface에 대한 포인터를 포함하고 Actor :: getSurface는 SDL_Surface에 대한 포인터를 반환합니다.SDL_Surface 클래스가 NULL이되는 클래스
물론 더 많은 코드가 문제를 해결하는 데 도움이된다고 생각하면 공유하게되어 기쁩니다.
내 프로그램의 출력은 다음과 같습니다 나는 코드의 중요 부분을 잘라
--Surface was loaded.
Surface is NULL after loading.
.
MAIN.CPP :
SDL_Init(SDL_INIT_EVERYTHING);
Actor sprite;
sprite.loadSurface("images/bg.bmp");
if(sprite.getSurface() == NULL)
std::clog << "Surface is NULL after loading." << std::endl;
Actor.cpp는
bool Actor::loadSurface(std::string t_filename)
{
std::clog << "-ACTOR " << m_id << " LOADSURFACE" << std::endl;
SDL_Surface * loadedImage = NULL;
m_surface = NULL;
loadedImage = IMG_Load(t_filename.c_str());
if(loadedImage != NULL)
{
std::clog << "--Surface was loaded." << std::endl;
m_surface = SDL_DisplayFormatAlpha(loadedImage);
SDL_FreeSurface(loadedImage);
return true;
}
std::clog << "--Surface was not loaded." << std::endl;
return false;
}
우리에게 전체 Actor 클래스보기 –
Actor.cpp http://pastebin.com/0PVhuYuU –
Actor.h http://pastebin.com/ZzFsTTUF –