LazyFoo의 멋진 튜토리얼 (http://lazyfoo.net/tutorials/SDL/10_color_keying/index.php)을 기반으로하는 간단한 색상 키 엔진 예제를 구현하려고하지만 실행하려고하면 EXC_BAD_ACCESS (코드 = 1, address = 0x0) 포인터가 null인지 여부를 테스트하려고한다는 사실에도 불구하고. 여기NULL을 확인하려고 할 때 EXC_BAD_ACCESS
//Texture wrapper class
class LTexture
{
public:
//Initializes variables
LTexture();
//Deallocates memory
~LTexture();
//Loads image at specified path
bool loadFromFile(std::string path);
//Deallocates texture
void free();
//Renders a texture at a given point
void render(int x, int y);
//Gets an image's dimensions
int getWidth();
int getHeight();
private:
//The actual hardware texture
SDL_Texture* mTexture = NULL;
//Image dimensions
int mWidth;
int mHeight;
};
및 초기화하기가 그리고 방법을 파괴 :
LTexture::LTexture()
{
//Initialize
mTexture = NULL;
mWidth = 0;
mHeight = 0;
printf("I initialized");
}
LTexture::~LTexture()
{
free();
}
을 그리고 내 오류가 LTexture::free
방법에있다 여기에 클래스의 모습입니다. 내가 테스트 할 때 mTexture 내가 유효한다고 생각하는 NULL이지만, 어떤 이유로 그렇지 않은 경우
void LTexture::free()
{
//Free texture if it exists
if (mTexture != NULL) //HERE IS THE ISSUE. WHAT IS WRONG WITH THIS?
{
SDL_DestroyTexture(mTexture);
mTexture = NULL;
mWidth = 0;
mHeight = 0;
}
}
당신이 온라인에서 볼 수 있듯이
는 문제가 나타납니다. 내가 도대체 뭘 잘못하고있는 겁니까? 코드 도움이 더 많이 게시됩니까?
예, 그렇습니다. 아마도 주위에 텍스처를 복사하고 있지만 코드가 올바르게 처리하지 못합니다. – user3684240
나는 이해하지 못한다 ... 어디에서 텍스처를 복사하고 싶습니까? 나는 텍스처가 복사되었는지 아닌지 free()가 신경 쓰지 않을 것이라고 생각했다. – WulffHunter
그건 그가 의미하는 것이 아닙니다. 1.'LTexture (const LTexture &) = delete;'를 클래스 정의에 넣으십시오. 2. 컴파일하면 개체 클래스의 인스턴스를 복사하는 위치가 곧 보입니다 (더 이상 수행 할 수 없기 때문입니다). 자세한 내용은 [Three of Rule] (https://en.wikipedia.org/wiki/Rule_of_three_ (C % 2B % 2B_programming))을 참조하십시오. – WhozCraig