From fadd885c805eb91d254f8626655f4086ef96ba8a Mon Sep 17 00:00:00 2001 From: Allanis Date: Wed, 22 Jan 2014 15:32:30 +0000 Subject: [PATCH] [Fix] No longer seg fault when player dies and enemies keep on kicking each others ass. --- src/joystick.c | 4 ++-- src/weapon.c | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/joystick.c b/src/joystick.c index dc15414..f0fe450 100644 --- a/src/joystick.c +++ b/src/joystick.c @@ -48,13 +48,13 @@ int joystick_use(int indjoystick) { /* Might as well close it if it is open already. */ SDL_JoystickClose(joystick); /* Start using the joystick. */ - LOG("Using joystick %d", indjoystick); joystick = SDL_JoystickOpen(indjoystick); if(joystick == NULL) { WARN("Error opening joystick %d [%s]", indjoystick, SDL_JoystickName(indjoystick)); return -1; } + LOG("Using joystick %d - %s", indjoystick, SDL_JoystickName(indjoystick)); DEBUG("\t\tWith %d axes, %d buttons, %d balls, and %d hats", SDL_JoystickNumAxes(joystick), SDL_JoystickNumButtons(joystick), SDL_JoystickNumBalls(joystick), SDL_JoystickNumHats(joystick)); @@ -81,7 +81,7 @@ int joystick_init(void) { numjoysticks = SDL_NumJoysticks(); LOG("%d joystick%s detected", numjoysticks, (numjoysticks==1)?"":"s"); for(i = 0; i < numjoysticks; i++) - LOG("\t\t%d. %s", i, SDL_JoystickName(i)); + DEBUG(" %d. %s", i, SDL_JoystickName(i)); /* Enable joystick events. */ SDL_JoystickEventState(SDL_ENABLE); diff --git a/src/weapon.c b/src/weapon.c index 48111fa..9348072 100644 --- a/src/weapon.c +++ b/src/weapon.c @@ -597,7 +597,8 @@ static void weapon_hit(Weapon* w, Pilot* p, WeaponLayer layer, Vec2* pos) { /* Someone should let the ai know it's been attacked. */ if(!pilot_isPlayer(p)) { - if((player->target == p->id) || (RNGF() > 0.33)) { /* 33% chance. */ + if((player != NULL) && + ((player->target == p->id) || (RNGF() > 0.33))) { /* 33% chance. */ parent = pilot_get(w->parent); if((parent->faction == FACTION_PLAYER) && (!pilot_isFlag(p, PILOT_HOSTILE) || (RNGF() < 0.5))) { /* 50% chance. */ @@ -638,7 +639,8 @@ static void weapon_hitBeam(Weapon* w, Pilot* p, WeaponLayer layer, /* Inform the ai it has been attacked, useless if player. */ if(!pilot_isPlayer(p)) { - if((player->target == p->id) || (RNGF() < 0.30*dt)) { /* 30% chance per second. */ + if((player != NULL) && + ((player->target == p->id) || (RNGF() < 0.30*dt))) { /* 30% chance per second. */ parent = pilot_get(w->parent); if((parent->faction == FACTION_PLAYER) && (!pilot_isFlag(p, PILOT_HOSTILE) || (RNGF() < 0.5))) { /* 50% chance. */