0
C++의 SDL_BlitSurface에서 세그먼트 오류가 발생합니다.SDL_BlitSurface 분할 오류
여기
void Screen::draw(float x, float y, Texture* source, SDL_Rect* clip)
{
SDL_Rect offset;
offset.x = x;
offset.y = y;
if (source->myimage == NULL) throw 5;
if (this->screen == NULL) throw 6;
SDL_BlitSurface(source->myimage, NULL, this->screen, &offset);
}
다음과 같이 텍스처가 정의로 구현되는 코드 (mainScreen이 화면 클래스의 인스턴스)
mainScreen->draw(0, 0, background, NULL);
및 Screen 클래스의 draw 함수입니다 :
class Texture
{
public:
Texture(std::string imagepath);
~Texture();
private:
SDL_Surface* myimage;
float width;
float height;
friend class Screen;
//friend void Screen::draw(float x, float y, Texture source, SDL_Rect* clip);
};
#include "Texture.h"
Texture::Texture(std::string filepath)
{
// Initialize the image to NULL to avoid any pointer issues
myimage = NULL;
// OPTIMIZED FOR PNGs
SDL_Surface* loadedImage = NULL;
SDL_Surface* optimizedImage = NULL;
loadedImage = IMG_Load(filepath.c_str());
if (loadedImage != NULL)
{
optimizedImage = SDL_DisplayFormatAlpha(loadedImage); // Notice no colour keying (use transparent PNGs)
}
myimage = optimizedImage;
SDL_FreeSurface(loadedImage);
SDL_FreeSurface(optimizedImage);
if (myimage == NULL)
{
// Some kind of error
throw 4;
}
}
Texture::~Texture()
{
SDL_FreeSurface(myimage);
}
이미지가 텍스처 클래스에로드되는 영역을 밟았으며 정상적으로 작동하는 것 같습니다. 또한 별도의 기능으로 SDL_FillRect를 사용할 때 this->screen
이 올바르게로드되었다는 것을 알고 있습니다.
문제를 나타내는 완전한 최소 예를 게시하십시오. – genpfault