Its because you are deleting the image in the Image destructor although this might not be a bad thing.
Its important to know that when you call any function, the arguments are created again and used inside the function, then they go out of scope.
So:
void Sprite::new_sprite ( Image ImageInstance, float X, float Y )
{
dbSprite ( get_open_ID (), X, Y, ImageInstance.ImageID );
PosX = X;
PosY = Y;
ItsImage = ImageInstance;
}
Here, a new Image is being created called ImageInstance, then when the function ends it goes out of scope, calling the destructor and as it shares the ID of the Image object passed in to the function it is deleting that image:
Image::~Image( void )
{
dbDeleteImage ( ImageID );
}
So, you might want to take this out of the destructor and create a deleteImage function, the alternative may be to use references, its quite straight forward and what it does is it stops another instance of Image being created, this will also speed up your program.
References:
Add a '&' sign to the Image argument in your new_sprite function like this:
void Sprite::new_sprite ( Image &ImageInstance, float X, float Y )
{
dbSprite ( get_open_ID (), X, Y, ImageInstance.ImageID );
PosX = X;
PosY = Y;
ItsImage = ImageInstance;
}
Dont forget to change the function declaration as well:
class Sprite
{
public:
float PosX, PosY;
void new_sprite ( Image &ImageInstance, float X, float Y );
Sprite ( void );
~Sprite ( void );
This just tells the program to use the same Image object inside that function and not create another temporary one. I know its alot to take in but it will be worth it in the end.