[Solved] SDL crashing at blit
Posted: Sat Mar 12, 2011 11:41 am
Basically, I have a function that blits for me and it is crashing when I try to blit a bullet I create.
So first, I have an abstract base class named "Ship" that contains this:
Then I have a derived class named "Player" that tries to add to its vector a MedBullet, which derives from bullet:
Then when I try to do the events for the bullets:
Show is an abstract base function in Bullets, but in MedBullet it is:
So at bullets->show(); my game terminates with status 3. Any help?
So first, I have an abstract base class named "Ship" that contains this:
Code: Select all
std::vector<Bullet*> bullets;
Code: Select all
void Player::shoot()
{
if(wantShoot == true)
{
if(bulletCount.is_started()==false || bulletCount.get_ticks()>200)
{
MedBullet bullet(x+(images[EplayerShip]->w/2)-5,y-7);
bullets.push_back(&bullet);
if(bulletCount.is_started() == false)
{
bulletCount.start();
}else{
bulletCount.stop();
bulletCount.start();
}
}
}
}
Code: Select all
for(int i = 0; i < (int)bullets.size(); i++)
{
bullets[i]->show(); //It crashes here
Code: Select all
void show()
{
apply_surface(x,y,images[EmedBullet],screen,NULL);
}
//apply surface
void apply_surface(int x, int y, SDL_Surface * source, SDL_Surface * destination, SDL_Rect* clips)
{
SDL_Rect offset;
offset.x=x;
offset.y=y;
if(source != NULL)
{
SDL_BlitSurface(source, clips, destination, &offset);
}
}