SDL_Blit problem

Howdy again folks!
Alright, I’m making this arcade shooter, and currently I am working on the
HUD (Heads Up Display), and I am having this problem when it comes to
Blitting.

Here is some code for ya.
HUD.H
#ifndef __hud_h
#define __hud_h

#include “main.h”

class HUD {
public:
HUD();
~HUD();

void DRAW(SDL_Surface *screen);
private:
SDL_Surface *energy_bar;
SDL_Surface *health_bar;

SDL_Rect e_bar_rect;
SDL_Rect h_bar_rect;
};

#endif

HUD.CPP
#include “hud.h”

void HUD::DRAW(SDL_Surface *screen) {
SDL_BlitSurface(energy_bar, NULL, screen, &e_bar_rect);
SDL_BlitSurface(health_bar, NULL, screen, &h_bar_rect);
}

HUD::~HUD() {
SDL_FreeSurface(energy_bar);
}

HUD::HUD() {
energy_bar = SDL_LoadBMP(“images/bar_energy.bmp”);
health_bar = SDL_LoadBMP(“images/bar_health.bmp”);

e_bar_rect.x = 0;
e_bar_rect.y = 0;
e_bar_rect.w = 200;
e_bar_rect.h = 20;

h_bar_rect.x = 0;
h_bar_rect.y = 40;
h_bar_rect.w = 200;
h_bar_rect.h = 20;
}

Alright, I get NO errors when it comes to compiling… but when I run it, it
seg faults (And that’s just not nice).
Now… Get this! When I remove all the code for the health bar(health_bar,
h_bar_rect), it blits just fine (only the energy bar).
WHY?

-Bryan Arant

— Bryan Arant skrev: > Howdy
again folks!

Alright, I’m making this arcade shooter, and
currently I am working on the
HUD (Heads Up Display), and I am having this problem
when it comes to
Blitting.

void HUD::DRAW(SDL_Surface *screen) {
SDL_BlitSurface(energy_bar, NULL, screen,
&e_bar_rect);
SDL_BlitSurface(health_bar, NULL, screen,
&h_bar_rect);
}

I believe the correct blitting args should be:
SDL_BlitSurface(energy_bar, &e_bar_rect, screen, 0);

I think you mixed up the source rectangle with the
destination rectangle

A quick look at the SDL_BlitSurface prototype in the
sdl_video header should clear things up

/Anders_____________________________________________________
Do You Yahoo!?
se.yahoo.com

Some error checking when loading the bitmaps from disk might help? Other
than that (to my eyes), the code looks ok. Also, are you compiling with
the -Wall switch? This could tell you many things you may have missed
(assuming gcc on linux :slight_smile:

Bryan Arant wrote:> Howdy again folks!

Alright, I’m making this arcade shooter, and currently I am working on the
HUD (Heads Up Display), and I am having this problem when it comes to
Blitting.

Here is some code for ya.
HUD.H
#ifndef __hud_h
#define __hud_h

#include “main.h”

class HUD {
public:
HUD();
~HUD();

void DRAW(SDL_Surface *screen);
private:
SDL_Surface *energy_bar;
SDL_Surface *health_bar;

SDL_Rect e_bar_rect;
SDL_Rect h_bar_rect;
};

#endif

HUD.CPP
#include “hud.h”

void HUD::DRAW(SDL_Surface *screen) {
SDL_BlitSurface(energy_bar, NULL, screen, &e_bar_rect);
SDL_BlitSurface(health_bar, NULL, screen, &h_bar_rect);
}

HUD::~HUD() {
SDL_FreeSurface(energy_bar);
}

HUD::HUD() {
energy_bar = SDL_LoadBMP(“images/bar_energy.bmp”);
health_bar = SDL_LoadBMP(“images/bar_health.bmp”);

e_bar_rect.x = 0;
e_bar_rect.y = 0;
e_bar_rect.w = 200;
e_bar_rect.h = 20;

h_bar_rect.x = 0;
h_bar_rect.y = 40;
h_bar_rect.w = 200;
h_bar_rect.h = 20;
}

Alright, I get NO errors when it comes to compiling… but when I run it,
it seg faults (And that’s just not nice).
Now… Get this! When I remove all the code for the health bar(health_bar,
h_bar_rect), it blits just fine (only the energy bar).
WHY?

-Bryan Arant

  • Mik Mifflin

I thought that SDL_BlitSurface() was

SDL_BlitSurface(src surface, src rect, dest surface, dest rect)…

That’s still not it, If I remove all the code for the health bar, the energy
bar blits just fine.

-Bryan Arant

“Anders Lowgren” wrote in message
news:<mailman.1009664106.24553.sdl at libsdl.org>…> — Bryan Arant skrev: > Howdy

again folks!

Alright, I’m making this arcade shooter, and
currently I am working on the
HUD (Heads Up Display), and I am having this problem
when it comes to
Blitting.

void HUD::DRAW(SDL_Surface *screen) {
SDL_BlitSurface(energy_bar, NULL, screen,
&e_bar_rect);
SDL_BlitSurface(health_bar, NULL, screen,
&h_bar_rect);
}

I believe the correct blitting args should be:
SDL_BlitSurface(energy_bar, &e_bar_rect, screen, 0);

I think you mixed up the source rectangle with the
destination rectangle

A quick look at the SDL_BlitSurface prototype in the
sdl_video header should clear things up

/Anders


Do You Yahoo!?
se.yahoo.com


Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.298 / Virus Database: 161 - Release Date: 11/13/2001