summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorblaise <blaise@macbook-ubuntu.(none)>2011-06-19 23:10:43 -0700
committerblaise <blaise@macbook-ubuntu.(none)>2011-06-19 23:10:43 -0700
commit49b88f9f5c8c4938af915a0e1e862ce42e0e37da (patch)
tree40fc2c6fac5baa42979b063299ececd29d9d17b3
parentcd4103dab21a214eff427241253d1b8483905719 (diff)
downloadnyancat-49b88f9f5c8c4938af915a0e1e862ce42e0e37da.tar.gz
nyancat-49b88f9f5c8c4938af915a0e1e862ce42e0e37da.tar.bz2
nyancat-49b88f9f5c8c4938af915a0e1e862ce42e0e37da.zip
Added Johnson's memory error handling and took out some unneeded commented code
-rw-r--r--nyan.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/nyan.c b/nyan.c
index 38b676a..a9d4c1d 100644
--- a/nyan.c
+++ b/nyan.c
@@ -46,6 +46,7 @@ static void cleanup(void);
static void clear_screen(void);
static void draw_cats(unsigned int frame);
static void draw_sparkles(void);
+static void errout(char *str);
static void fillsquare(SDL_Surface* surf, int x, int y, int w, int h, Uint32 col);
static void handle_args(int argc, char** argv);
static void handle_input(void);
@@ -89,6 +90,8 @@ add_sparkle(void) {
sparkle_instance* new;
new = malloc(sizeof(sparkle_instance));
+ if(!new)
+ errout("Could not allocate new sparkle instance memory in add_sparkle.");
new->loc.x = screen->w + 80;
new->loc.y = (rand() % (screen->h + sparkle_img[0]->h)) - sparkle_img[0]->h;
@@ -115,6 +118,9 @@ add_cat(unsigned int x, unsigned int y) {
cat_instance* new;
new = malloc(sizeof(cat_instance));
+ if(!new)
+ errout("Could not allocate new cat instance memory in add_cat.");
+
new->loc.x = x;
new->loc.y = y;
new->next = NULL;
@@ -167,13 +173,10 @@ draw_cats(unsigned int frame) {
while (c) {
pos.x = c->loc.x;
pos.y = c->loc.y;
-// pos.w = screen->w;
-// pos.h = pos.w/cat_img[frame]->h*cat_img[frame]->w;
if(frame < 2)
pos.y -= 5;
SDL_BlitSurface( stretch_cat[frame], NULL, screen, &pos );
-// SDL_SoftStretch(cat_img[frame],NULL,screen,NULL);
c = c->next;
}
}
@@ -192,6 +195,13 @@ draw_sparkles() {
}
static void
+errout (char *str) {
+ if (str)
+ puts(str);
+ exit(1);
+}
+
+static void
fillsquare(SDL_Surface* surf, int x, int y, int w, int h, Uint32 col) {
int i, e;