So I've been wrestling with this problem for a few days now. So I have a entity class and I thought I would use a vector to make it so i could have a dynamic array of the entity's. It crashed horribly and i learned that in my SmartImage class (located inside the entity class) was only making a shallow copy. So i'm trying to make a deep copy using the copy constructor. My program compiles but it crashes as soon as it launches. It seems even initializing the SmartImage class will cause it to crash. What am i doing wrong?
SmartImage.h
class SmartImage
{
private:
bool image_loaded;
public:
SmartImage();
~SmartImage();
// copy constructor:
SmartImage (const SmartImage& param);
SDL_Surface *surface;
void load(std::string filename);
void copy_surface(SDL_Surface *target_surface);
};
#include"SmartImage.cpp"
SmartImage.cpp
SmartImage::SmartImage()
{
surface=NULL;
image_loaded = false;
}
SmartImage::~SmartImage()
{
SDL_FreeSurface(surface);
}
// copy constructor
SmartImage::SmartImage (const SmartImage& param)
{
surface = SDL_DisplayFormat(param.surface);
}
void SmartImage::load(std::string filename)
{
if(image_loaded == false)
{
surface = load_image(filename);
image_loaded = true;
}
else
{
SDL_FreeSurface(surface);
surface = load_image(filename);
}
}
void SmartImage::copy_surface(SDL_Surface *temp_surface)
{
if(image_loaded == true)
{
SDL_FreeSurface(surface);
}
surface = SDL_DisplayFormat(temp_surface);
image_loaded = true;
}