デストラクタBlock
を呼び出すクラスがあります。SDL_FreeSurface(surface)
でブロックのmain()
インスタンスを作成すると、オブジェクトは適切に機能しますが、データ メンバーとしてControl
持つ別のクラスで使用するとvector<Block> block_vector
、 のインスタンスを に追加するとプログラムがクラッシュしBlock
ますblock_vector
。Block
を呼び出すときのデストラクタの問題を絞り込みましたSDL_FreeSurface(surface)
。ベクターにオブジェクトを追加することは何か関係がありますか? 何が問題ですか?
class Block{
public:
Block(int x, int y);
~Block();
void Load_Image(MediaFunctions &M_Functions);
void SetPosition(int x, int y);
void BlitBlock(SDL_Event &event, MediaFunctions &M_Functions, SDL_Surface *destination);
bool DetectionNames(SDL_Event &event, MediaFunctions &M_Functions, SDL_Surface *destination);
bool DetectionHours(SDL_Event &event, MediaFunctions &M_Functions, SDL_Surface *destination);
bool return_error();
private:
SDL_Surface *block_surface_names;
SDL_Surface *block_surface_hours;
SDL_Surface *block_names_detected;
SDL_Surface *block_hours_detected;
SDL_Rect block_rect_names;
SDL_Rect block_rect_hours;
bool error;
};
//the problem
Block::~Block(){
SDL_FreeSurface(block_surface_hours);
SDL_FreeSurface(block_surface_names);
SDL_FreeSurface(block_hours_detected);
SDL_FreeSurface(block_names_detected);
}
//when doing this
void Control::HandleEvents(SDL_Event &event, MediaFunctions &M_Functions){
if(event.type == SDL_KEYDOWN){
if( event.key.keysym.sym == SDLK_a ){
//append a block instance
BlockVector.push_back(Block (Block(100,100)));
BlockVector.at(block_index).Load_Image(M_Functions);
block_index++;
}
}
}